Class: RRule::Humanizer
- Inherits:
-
Object
- Object
- RRule::Humanizer
- Defined in:
- lib/rrule/humanizer.rb
Overview
Constant Summary collapse
- OPTION_ATTRIBUTE_RE =
/_option/.freeze
- DAY_NAMES =
%w[ Sunday Monday Tuesday Wednesday Thursday Friday Saturday ].freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rrule ⇒ Object
readonly
Returns the value of attribute rrule.
Instance Method Summary collapse
-
#initialize(rrule, options) ⇒ Humanizer
constructor
A new instance of Humanizer.
-
#method_missing(method_name, *args) ⇒ Object
Return nil if we’re trying to access an option that isn’t present.
- #respond_to_missing?(method_name) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(rrule, options) ⇒ Humanizer
Returns a new instance of Humanizer.
21 22 23 24 25 26 27 |
# File 'lib/rrule/humanizer.rb', line 21 def initialize(rrule, ) @rrule = rrule @options = # Define instance method for each of the options. .each { |name, value| define_singleton_method("#{name}_option") { value } } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Return nil if we’re trying to access an option that isn’t present.
45 46 47 48 49 50 51 |
# File 'lib/rrule/humanizer.rb', line 45 def method_missing(method_name, *args) if method_name.to_s.match?(OPTION_ATTRIBUTE_RE) nil else super end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/rrule/humanizer.rb', line 7 def @options end |
#rrule ⇒ Object (readonly)
Returns the value of attribute rrule.
7 8 9 |
# File 'lib/rrule/humanizer.rb', line 7 def rrule @rrule end |
Instance Method Details
#respond_to_missing?(method_name) ⇒ Boolean
53 54 55 |
# File 'lib/rrule/humanizer.rb', line 53 def respond_to_missing?(method_name) super || method_name.to_s.match?(OPTION_ATTRIBUTE_RE) end |
#to_s ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rrule/humanizer.rb', line 29 def to_s @buffer = 'every' send freq_option.downcase raise 'Implement Until' if until_option if count_option add 'for' add count_option add plural?(count_option) ? 'times' : 'time' end @buffer end |