Class: RRule::Humanizer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options)
  @rrule = rrule
  @options = options

  # Define instance method for each of the options.
  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

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/rrule/humanizer.rb', line 7

def options
  @options
end

#rruleObject (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

Returns:

  • (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_sObject



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