Skip to content

Commit

Permalink
Refactor CameraWidget::Base#value
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Nov 24, 2023
1 parent 545980a commit ce6d8f2
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/gphoto2/camera_widgets/base.cr
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,20 @@ module GPhoto2
get_info.not_nil!
end

private EMPTY_VALUES = {"none"}
private EMPTY_VALUES = {nil, "none"}

# Returns widget `value` unless it's empty or is known to be
# an empty string, like `none` or raises `NotImplementedError`.
def value?
begin
value = self.value
rescue NotImplementedError
return
end
string_value = value.to_s.presence
if !string_value || string_value.downcase.in?(EMPTY_VALUES)
return
end
value
rescue NotImplementedError
end

# Returns widget value.
def value
get_value
get_value.tap do |value|
return if value.to_s.downcase.presence.in?(EMPTY_VALUES)
end
end

# Sets widget value.
Expand Down

0 comments on commit ce6d8f2

Please sign in to comment.