Permalink
Browse files

Define callback for Program

  • Loading branch information...
1 parent 7e0c0c5 commit 76de99d2b9ff3a93f760d0566950069a07991c89 @r7kamura committed Apr 4, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/syoboi_calendar/program.rb
@@ -12,7 +12,8 @@ class Program
:title => "TitleFull"
}
- # :method_name => "NameInSyoboiCalendarResponse"
+ # (1) :method_name => "NameInSyoboiCalendarResponse"
+ # (2) :method_name => ["NameInSyoboiCalendarResponse", callback]
EXT_PARAM_MAP = {
:program => {
:channel_epg_url => "ChEPGURL",
@@ -21,8 +22,8 @@ class Program
:comment => "Comment",
:config_flag => "ConfFlag",
:count => "Count",
- :end_time => "EdTime",
- :start_time => "StTime",
+ :end_time => ["EdTime", proc { |val| Time.at(val.to_i) }],
+ :start_time => ["StTime", proc { |val| Time.at(val.to_i) }],
:subtitle => "SubTitle",
:subtitle2 => "SubTitle2"
},
@@ -81,7 +82,14 @@ def update_detail(type)
hash = Agent.json(:Req => REQ_MAP[type], :PID => @pid, :TID => @tid)
hash = hash[hash.keys.first]
hash = hash[hash.keys.first]
- EXT_PARAM_MAP[type].each { |k, v| @blob[k] = hash[v] }
+
+ EXT_PARAM_MAP[type].each do |k, v|
+ if v.is_a?(Array)
@hotchpotch

hotchpotch Apr 5, 2012

v.kind_of?(Array)

is_a? と同等だけど、kind_of? を Ruby ではよく使う

+ @blob[k] = v[1].call(hash[v[0]])
+ else
+ @blob[k] = hash[v]
+ end
+ end
end
end
end

0 comments on commit 76de99d

Please sign in to comment.