-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add group function #to_s and #inspect (#127)
Signed-off-by: Jimmy Tanagra <[email protected]>
- Loading branch information
Showing
3 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenHAB | ||
module Core | ||
module Items | ||
java_import org.openhab.core.items.GroupFunction | ||
|
||
# | ||
# Adds `#to_s` and `#inspect` to group function. | ||
# | ||
# @example | ||
# # Group:SWITCH:OR(ON,OFF) Switches | ||
# logger.info "The Switches group function is: #{Switches.function}" # => "OR" | ||
# logger.info "The Switches group function: #{Switches.function.inspect}" # => "OR(ON,OFF)" | ||
# | ||
module GroupFunction | ||
# | ||
# Returns the group function as an uppercase string | ||
# @return [String] | ||
# | ||
def to_s | ||
self.class.simple_name.upcase | ||
end | ||
|
||
# | ||
# Returns the group function and its parameters as a string | ||
# @return [String] | ||
# | ||
def inspect | ||
params = parameters.map(&:inspect).join(",") | ||
params = "(#{params})" unless params.empty? | ||
"#{self}#{params}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters