class HammerCLI::Options::Matcher
Public Class Methods
new(filter)
click to toggle source
# File lib/hammer_cli/options/matcher.rb, line 7 def initialize(filter) @filter = filter end
Public Instance Methods
matches?(option)
click to toggle source
# File lib/hammer_cli/options/matcher.rb, line 11 def matches?(option) @filter.each do |attribute, filter| return false if !attribute_matches?(option, attribute, filter) end return true end
Protected Instance Methods
attribute_matches?(option, attribute, filter)
click to toggle source
# File lib/hammer_cli/options/matcher.rb, line 20 def attribute_matches?(option, attribute, filter) if filter.is_a? Array return filter.any? {|filter_part| attribute_matches?(option, attribute, filter_part)} elsif filter.is_a? Regexp return attribute_matches_regexp?(option, attribute, filter) else return attribute_matches_value?(option, attribute, filter) end end
attribute_matches_regexp?(option, attribute, filter)
click to toggle source
# File lib/hammer_cli/options/matcher.rb, line 34 def attribute_matches_regexp?(option, attribute, filter) get_attribute_value(option, attribute) =~ filter end
attribute_matches_value?(option, attribute, filter)
click to toggle source
# File lib/hammer_cli/options/matcher.rb, line 30 def attribute_matches_value?(option, attribute, filter) get_attribute_value(option, attribute) == filter end
get_attribute_value(option, attribute_name)
click to toggle source
# File lib/hammer_cli/options/matcher.rb, line 38 def get_attribute_value(option, attribute_name) option.send(attribute_name) rescue NoMethodError nil end