Class: Vishnu::StandardTime::Plan
- Inherits:
-
Object
- Object
- Vishnu::StandardTime::Plan
- Defined in:
- lib/vishnu/standard_time.rb
Defined Under Namespace
Classes: Block
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
Instance Method Summary collapse
- #block(name, flows: nil, seconds: nil, minutes: nil, hours: nil) ⇒ Object
-
#initialize ⇒ Plan
constructor
A new instance of Plan.
- #percent_of_day ⇒ Object
- #summary ⇒ Object
- #to_h ⇒ Object
- #total_flows ⇒ Object
- #total_minutes ⇒ Object
Constructor Details
#initialize ⇒ Plan
Returns a new instance of Plan.
142 143 144 |
# File 'lib/vishnu/standard_time.rb', line 142 def initialize @blocks = [] end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
140 141 142 |
# File 'lib/vishnu/standard_time.rb', line 140 def blocks @blocks end |
Instance Method Details
#block(name, flows: nil, seconds: nil, minutes: nil, hours: nil) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/vishnu/standard_time.rb', line 146 def block(name, flows: nil, seconds: nil, minutes: nil, hours: nil) count = flows || Vishnu::StandardTime.flows_for(seconds: seconds, minutes: minutes, hours: hours) count = Integer(count) raise ArgumentError, "block flows must be positive" unless count.positive? @blocks << Block.new(name: name.to_s, flows: count) end |
#percent_of_day ⇒ Object
162 163 164 |
# File 'lib/vishnu/standard_time.rb', line 162 def percent_of_day (total_flows.to_f / Vishnu::StandardTime::FLOWS_PER_DAY) * 100 end |
#summary ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/vishnu/standard_time.rb', line 175 def summary width = [blocks.map { |b| b.name.length }.max || 4, 4].max lines = blocks.map do |entry| "%#{width}s %9s flows %7.2f min %6.2f%%" % [ entry.name, Vishnu::StandardTime.format_number(entry.flows), entry.minutes, entry.percent_of_day ] end lines << "" lines << "%#{width}s %9s flows %7.2f min %6.2f%%" % [ "Total", Vishnu::StandardTime.format_number(total_flows), total_minutes, percent_of_day ] lines.join("\n") end |
#to_h ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/vishnu/standard_time.rb', line 166 def to_h { blocks: blocks.map(&:to_h), total_flows: total_flows, total_minutes: total_minutes, percent_of_day: percent_of_day.round(4) } end |
#total_flows ⇒ Object
154 155 156 |
# File 'lib/vishnu/standard_time.rb', line 154 def total_flows blocks.sum(&:flows) end |
#total_minutes ⇒ Object
158 159 160 |
# File 'lib/vishnu/standard_time.rb', line 158 def total_minutes Vishnu::StandardTime.minutes_for(flows: total_flows) end |