Class: Jpcalendar::WeekdayScale::WeekDay
- Inherits:
-
Object
- Object
- Jpcalendar::WeekdayScale::WeekDay
- Defined in:
- lib/jpcalendar/weekday_scale.rb
Overview
WeekDay {{{
Constant Summary collapse
- WEEK_DAY =
[ WeekDayElem.new(0,"日","sun"), WeekDayElem.new(1,"月","mon"), WeekDayElem.new(2,"火","tue"), WeekDayElem.new(3,"水","wed"), WeekDayElem.new(4,"木","thu"), WeekDayElem.new(5,"金","fri"), WeekDayElem.new(6,"土","sat") ]
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(start_with_monday = false) ⇒ WeekDay
constructor
A new instance of WeekDay.
- #last ⇒ Object
-
#map ⇒ Object
もっとスマートにdeligateしたいなぁ.
-
#method_missing(method_name, *args) ⇒ Object
params: method_name メソッド名 *args 第1引数 week_day_メソッドで呼ばれた場合は options find_by_メソッドで呼ばれた場合は 検索対象の値 call example week_day_jpname(WEEK_DAY).
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
params: method_name メソッド名
*args 第1引数 week_day_メソッドで呼ばれた場合は options
find_by_メソッドで呼ばれた場合は 検索対象の値
call example week_day_jpname(WEEK_DAY)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jpcalendar/weekday_scale.rb', line 43 def method_missing(method_name,*args) if method_name =~ /^find_by_(.*)/ unless respond_to?(method_name.to_sym) self.instance_eval %Q{ def #{method_name}(id) if id.present? @wdays.select{|wd| wd.#{$1} == id }.first end end } end return send(method_name, args[0] ) end super end |
Instance Method Details
#each ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/jpcalendar/weekday_scale.rb', line 70 def each if block_given? @wdays.each{|wday| yield wday} else @wdays.each end end |
#last ⇒ Object
78 79 80 |
# File 'lib/jpcalendar/weekday_scale.rb', line 78 def last @wdays.last end |
#map ⇒ Object
もっとスマートにdeligateしたいなぁ
62 63 64 65 66 67 68 |
# File 'lib/jpcalendar/weekday_scale.rb', line 62 def map if block_given? @wdays.map{|wday| yield wday} else @wdays.map end end |