class Gyunyu::Command::Export::App

Constants

ESTIMATE_DAY
ESTIMATE_HOUR
ESTIMATE_MIN
TIME_FIELDS

Attributes

lists[R]
option[R]
token[R]

Public Class Methods

new() click to toggle source
# File lib/gyunyu/command/export/app.rb, line 11
def initialize
  @argv  ||= ARGV
  @token ||= Gyunyu::Token.get

  _init_lists
  _init_option( @argv )
end

Public Instance Methods

_init_lists() click to toggle source
return

Array

# File lib/gyunyu/command/export/app.rb, line 44
def _init_lists
  @lists ||= RTM::List.alive_all
end
_init_option( argv = nil ) click to toggle source
param

Array argv

return

Option

# File lib/gyunyu/command/export/app.rb, line 52
def _init_option( argv = nil )
  @option = Option.new( argv )
end
build_filter( filter = nil ) click to toggle source
param

String filter

return

String

# File lib/gyunyu/command/export/app.rb, line 72
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 ) click to toggle source
param

String filter

return

Object

# File lib/gyunyu/command/export/app.rb, line 145
def export( filter = nil )
  format_module.export( pickup_fields( filter ), fields )
end
fields() click to toggle source
return

Array

# File lib/gyunyu/command/export/app.rb, line 23
def fields
  ['list'] + option.fields.map { |f|
    if f == 'estimate'
      [ESTIMATE_DAY, ESTIMATE_HOUR, ESTIMATE_MIN]
    else
      f
    end
  }.flatten
end
find_list( id ) click to toggle source
param

String id

return

RTM::List

# File lib/gyunyu/command/export/app.rb, line 99
def find_list( id )
  @lists.find { |list|
    list.id == id
  }
end
format_module() click to toggle source
return

Module

# File lib/gyunyu/command/export/app.rb, line 36
def format_module
  format = option.format.to_s.capitalize
  Format.const_get(format)
end
localtime( time ) click to toggle source
param

String

return

Time

# File lib/gyunyu/command/export/app.rb, line 161
def localtime( time )
  if time.size > 0
    Time.parse( time ).localtime
  else
    time
  end
end
pickup_fields( filter = nil ) click to toggle source
param

String filter

return

Array

# File lib/gyunyu/command/export/app.rb, line 109
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() click to toggle source
# File lib/gyunyu/command/export/app.rb, line 56
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 ) click to toggle source
param

String estimate

return

RtmTime

# File lib/gyunyu/command/export/app.rb, line 153
def split_estimate( estimate )
  ::RtmTime::Ja.parse(estimate)
end
task_list( filter = nil ) click to toggle source
param

String filter

return

RTM::Tasks::GetList

# File lib/gyunyu/command/export/app.rb, line 89
def task_list( filter = nil )
  RTM::Tasks::GetList.new( token,
                           nil,
                           filter ).invoke
end