Class: MizuhoBank::RepeatDateRange

Inherits:
Object
  • Object
show all
Defined in:
lib/mizuho_bank.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepeatDateRange

Returns a new instance of RepeatDateRange.



145
146
147
148
# File 'lib/mizuho_bank.rb', line 145

def initialize
  @start = RepeatDate.new
  @end = RepeatDate.new
end

Instance Attribute Details

#endObject

Returns the value of attribute end.



143
144
145
# File 'lib/mizuho_bank.rb', line 143

def end
  @end
end

#startObject

Returns the value of attribute start.



142
143
144
# File 'lib/mizuho_bank.rb', line 142

def start
  @start
end

Instance Method Details

#cover?(time, context = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
153
154
# File 'lib/mizuho_bank.rb', line 150

def cover? (time, context = Time.now)
  s = start_time(context)
  e = end_time(s)
  (s .. e).cover? (time)
end

#end_time(context = Time.now) ⇒ Object



164
165
166
# File 'lib/mizuho_bank.rb', line 164

def end_time(context = Time.now)
  Chronic.parse(translate_in_this_month(@end.to_s, context), :now => context)
end

#include?(*args) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/mizuho_bank.rb', line 156

def include? (*args)
  cover? *args
end

#start_time(context = Time.now) ⇒ Object



160
161
162
# File 'lib/mizuho_bank.rb', line 160

def start_time(context = Time.now)
  Chronic.parse(translate_in_this_month(@start.to_s, context), :now => context)
end

#to_s(context = Time.now) ⇒ Object



183
184
185
186
187
# File 'lib/mizuho_bank.rb', line 183

def to_s(context = Time.now)
  s = start_time(context)
  e = end_time(s)
  "#{s} - #{e}"
end

#translate_in_this_month(text, context = Time.now) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/mizuho_bank.rb', line 168

def translate_in_this_month(text, context=Time.now)
  if text.match(/(.*?)(.+) (.+) in this month(.*)/)
    month = context.strftime("%B")
    previous = Regexp.last_match(1)
    n = Regexp.last_match(2)
    wday = Regexp.last_match(3)
    last = Regexp.last_match(4)

    time = Chronic.parse("#{n} #{wday} in #{month}")
    time.strftime("#{previous} %Y/%m/%d #{last}")
  else
    text
  end
end