Class: Gyunyu::Command::Export::App
- Inherits:
-
Object
- Object
- Gyunyu::Command::Export::App
- Defined in:
- lib/gyunyu/command/export/app.rb
Constant Summary collapse
- TIME_FIELDS =
%w( created modified due added completed deleted )- ESTIMATE_DAY =
'estimate(d)'- ESTIMATE_HOUR =
'estimate(h)'- ESTIMATE_MIN =
'estimate(m)'
Instance Attribute Summary collapse
-
#lists ⇒ Object
readonly
Returns the value of attribute lists.
-
#option ⇒ Object
readonly
Returns the value of attribute option.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#_init_lists ⇒ Object
- return
-
Array.
-
#_init_option(argv = nil) ⇒ Object
- param
-
Array argv [return] Option.
-
#build_filter(filter = nil) ⇒ Object
- param
-
String filter [return] String.
-
#export(filter = nil) ⇒ Object
- param
-
String filter [return] Object.
-
#fields ⇒ Object
- return
-
Array.
-
#find_list(id) ⇒ Object
- param
-
String id [return] RTM::List.
-
#format_module ⇒ Object
- return
-
Module.
-
#initialize ⇒ App
constructor
A new instance of App.
-
#localtime(time) ⇒ Object
- param
-
String [return] Time.
-
#pickup_fields(filter = nil) ⇒ Object
- param
-
String filter [return] Array.
- #run ⇒ Object
-
#split_estimate(estimate) ⇒ Object
- param
-
String estimate [return] RtmTime.
-
#task_list(filter = nil) ⇒ Object
- param
-
String filter [return] RTM::Tasks::GetList.
Constructor Details
#initialize ⇒ App
12 13 14 15 16 17 18 |
# File 'lib/gyunyu/command/export/app.rb', line 12 def initialize @argv ||= ARGV @token ||= Gyunyu::Token.get _init_lists _init_option( @argv ) end |
Instance Attribute Details
#lists ⇒ Object (readonly)
Returns the value of attribute lists.
19 20 21 |
# File 'lib/gyunyu/command/export/app.rb', line 19 def lists @lists end |
#option ⇒ Object (readonly)
Returns the value of attribute option.
19 20 21 |
# File 'lib/gyunyu/command/export/app.rb', line 19 def option @option end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
19 20 21 |
# File 'lib/gyunyu/command/export/app.rb', line 19 def token @token end |
Instance Method Details
#_init_lists ⇒ Object
- return
-
Array
45 46 47 |
# File 'lib/gyunyu/command/export/app.rb', line 45 def _init_lists @lists ||= RTM::List.alive_all end |
#_init_option(argv = nil) ⇒ Object
- param
-
Array argv
- return
-
Option
53 54 55 |
# File 'lib/gyunyu/command/export/app.rb', line 53 def _init_option( argv = nil ) @option = Option.new( argv ) end |
#build_filter(filter = nil) ⇒ Object
- param
-
String filter
- return
-
String
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gyunyu/command/export/app.rb', line 73 def build_filter( filter = nil ) filters = [] filters << option.lists.map { |l| "list:#{l}" }.join(' or ') if option.lists.size > 0 filters << CustomFilter.filter[option.custom_filter] if option.custom_filter filters << option.filter if option.filter filters << filter if filter f = '(' + filters.join(') and (') + ')' STDERR.puts f f end |
#export(filter = nil) ⇒ Object
- param
-
String filter
- return
-
Object
146 147 148 |
# File 'lib/gyunyu/command/export/app.rb', line 146 def export( filter = nil ) format_module.export( pickup_fields( filter ), fields ) end |
#fields ⇒ Object
- return
-
Array
24 25 26 27 28 29 30 31 32 |
# File 'lib/gyunyu/command/export/app.rb', line 24 def fields ['list'] + option.fields.map { |f| if f == 'estimate' [ESTIMATE_DAY, ESTIMATE_HOUR, ESTIMATE_MIN] else f end }.flatten end |
#find_list(id) ⇒ Object
- param
-
String id
- return
-
RTM::List
100 101 102 103 104 |
# File 'lib/gyunyu/command/export/app.rb', line 100 def find_list( id ) @lists.find { |list| list.id == id } end |
#format_module ⇒ Object
- return
-
Module
37 38 39 40 |
# File 'lib/gyunyu/command/export/app.rb', line 37 def format_module format = option.format.to_s.capitalize Format.const_get(format) end |
#localtime(time) ⇒ Object
- param
-
String
- return
-
Time
162 163 164 165 166 167 168 |
# File 'lib/gyunyu/command/export/app.rb', line 162 def localtime( time ) if time.size > 0 Time.parse( time ).localtime else time end end |
#pickup_fields(filter = nil) ⇒ Object
- param
-
String filter
- return
-
Array
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/gyunyu/command/export/app.rb', line 110 def pickup_fields( filter = nil ) tasks = [] result = task_list( filter ) if result.respond_to? :each result.each { |l| list_name = find_list( l['id'] ).name tasks += Gyunyu::Expander.taskseries( l['taskseries'] ).map { |t| record = {'list' => list_name} option.fields.each { |f| val = if TIME_FIELDS.include?( f ) localtime( t[f] ) else t[f] end if f == 'estimate' e = split_estimate( t[f] ) record[ESTIMATE_DAY] = e.day record[ESTIMATE_HOUR] = e.hour record[ESTIMATE_MIN] = e.min else record[f] = val end } record } } end tasks end |
#run ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gyunyu/command/export/app.rb', line 57 def run if @argv.size > 0 if option.show_filter_list puts CustomFilter.filter.keys.sort else puts export( build_filter ) end else puts option.parser end end |
#split_estimate(estimate) ⇒ Object
- param
-
String estimate
- return
-
RtmTime
154 155 156 |
# File 'lib/gyunyu/command/export/app.rb', line 154 def split_estimate( estimate ) ::RtmTime::Ja.parse(estimate) end |
#task_list(filter = nil) ⇒ Object
- param
-
String filter
- return
-
RTM::Tasks::GetList
90 91 92 93 94 |
# File 'lib/gyunyu/command/export/app.rb', line 90 def task_list( filter = nil ) RTM::Tasks::GetList.new( token, nil, filter ).invoke end |