Class: Tlog::Command::Display
- Inherits:
-
Tlog::Command
- Object
- Tlog::Command
- Tlog::Command::Display
- Defined in:
- lib/tlog/command/display.rb
Instance Attribute Summary
Attributes inherited from Tlog::Command
#date_time_format, #seconds_format, #storage
Instance Method Summary collapse
- #description ⇒ Object
- #execute(input, output) ⇒ Object
-
#log_goal_valid(log, thresholds) ⇒ Object
Methods that filter which logs should be displayed.
- #log_owners_valid(log, thresholds) ⇒ Object
- #log_points_valid(log, thresholds) ⇒ Object
- #log_states_valid(log, thresholds) ⇒ Object
- #name ⇒ Object
- #options(parser, options) ⇒ Object
Instance Method Details
#description ⇒ Object
8 9 10 |
# File 'lib/tlog/command/display.rb', line 8 def description "displays information about time logs. command options contrain which time logs are displayed" end |
#execute(input, output) ⇒ Object
12 13 14 |
# File 'lib/tlog/command/display.rb', line 12 def execute(input, output) display(input.args[0], input., output) end |
#log_goal_valid(log, thresholds) ⇒ Object
Methods that filter which logs should be displayed
39 40 41 42 43 44 45 |
# File 'lib/tlog/command/display.rb', line 39 def log_goal_valid(log, thresholds) goal_threshold = thresholds[:goal] goal_threshold = ChronicDuration.parse(goal_threshold) return false unless log.goal goal_threshold >= log.goal ? valid = true : valid = false valid end |
#log_owners_valid(log, thresholds) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/tlog/command/display.rb', line 47 def log_owners_valid(log, thresholds) owners = thresholds[:owners] owners.each do |owner| return true if log.owner == owner end false end |
#log_points_valid(log, thresholds) ⇒ Object
55 56 57 58 59 |
# File 'lib/tlog/command/display.rb', line 55 def log_points_valid(log, thresholds) points_value = thresholds[:points] log.points >= points_value ? valid = true : valid = false valid end |
#log_states_valid(log, thresholds) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/tlog/command/display.rb', line 61 def log_states_valid(log, thresholds) states = thresholds[:states] states.each do |state| return true if log.state.downcase == state.downcase end false end |
#name ⇒ Object
4 5 6 |
# File 'lib/tlog/command/display.rb', line 4 def name "display" end |
#options(parser, options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tlog/command/display.rb', line 16 def (parser, ) parser. = "usage: tlog display #{$0} [options]" parser.on("-g", "--goal <goal_threshold>") do |goal| [:goal] = goal end parser.on("-o", "--owner a,b,c", Array, "Array of owners to display") do |owners| [:owners] = owners end parser.on("-p", "--points <points_threshold>") do |points| [:points] = points.to_i end parser.on("-s", "--state a,b,c", Array, "Array of states to display") do |states| [:states] = states end end |