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
- MONTH_NAMES =
%w[ January February March April May June July August September October November December ].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.
36 37 38 39 40 41 42 |
# File 'lib/rrule/humanizer.rb', line 36 def initialize(rrule, ) @rrule = rrule = # 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.
60 61 62 63 64 65 66 |
# File 'lib/rrule/humanizer.rb', line 60 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 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
68 69 70 |
# File 'lib/rrule/humanizer.rb', line 68 def respond_to_missing?(method_name) super || method_name.to_s.match?(OPTION_ATTRIBUTE_RE) end |
#to_s ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rrule/humanizer.rb', line 44 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 |