Class: Schedule
- Inherits:
-
Object
- Object
- Schedule
- Defined in:
- lib/energyplus/SchedulesCSV.rb
Instance Attribute Summary collapse
-
#hours_per_year ⇒ Object
Returns the value of attribute hours_per_year.
-
#name ⇒ Object
Returns the value of attribute name.
-
#table ⇒ Object
Returns the value of attribute table.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #close_table(this_table) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(s) ⇒ Schedule
constructor
A new instance of Schedule.
- #print_table ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(s) ⇒ Schedule
Returns a new instance of Schedule.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/energyplus/SchedulesCSV.rb', line 36 def initialize(s) @lines = s.split("\n") @name = make_schedule_name(@lines[0]) @type = @lines[1] @table = Array.new this_table = Array.new duration = "" this_cols = 0 open = false multi_duration = false (2..@lines.length-1).each do |idx| parts = CSV.parse_line(@lines[idx]) if parts[0].include?('Through') if open if (not this_table[-1][0] == 'Total Hours/Year') this_table.push(Array.new) this_table[-1].push('Total Hours/Year') if not multi_duration (1..this_cols-1).each {|i| this_table[-1].push("") } end multi_duration = true close_table(this_table) end this_table = Array.new duration = parts[0] open = true elsif parts[0]==('Hour') this_table.push(Array.new) this_cols = parts.length this_table[-1].push(parts[0]) if not multi_duration (1..this_cols-1).each {|i| this_table[-1].push(parts[i] + " (" + duration + ")") } elsif parts[0].include?('Total Hours/Day') this_table.push(Array.new) this_table[-1].push(parts[0]) if not multi_duration (1..this_cols-1).each {|i| this_table[-1].push(custom_print(parts[i].to_f, 4)) } elsif parts[0].include?('Total Hours/Week') this_table.push(Array.new) this_table[-1].push(parts[0]) if not multi_duration this_table[-1].push(custom_print(parts[1].to_f, 4)) (2..this_cols-1).each {|i| this_table[-1].push("") } elsif parts[0].include?('Total Hours/Year') @hours_per_year = parts[1].to_f this_table.push(Array.new) this_table[-1].push(parts[0]) if not multi_duration this_table[-1].push(custom_print(parts[1].to_f, 4)) (2..this_cols-1).each {|i| this_table[-1].push("") } else parts.delete_at(0) if multi_duration this_table.push(parts) end end close_table(this_table) #print_table if multi_duration end |
Instance Attribute Details
#hours_per_year ⇒ Object
Returns the value of attribute hours_per_year.
34 35 36 |
# File 'lib/energyplus/SchedulesCSV.rb', line 34 def hours_per_year @hours_per_year end |
#name ⇒ Object
Returns the value of attribute name.
34 35 36 |
# File 'lib/energyplus/SchedulesCSV.rb', line 34 def name @name end |
#table ⇒ Object
Returns the value of attribute table.
34 35 36 |
# File 'lib/energyplus/SchedulesCSV.rb', line 34 def table @table end |
#type ⇒ Object
Returns the value of attribute type.
34 35 36 |
# File 'lib/energyplus/SchedulesCSV.rb', line 34 def type @type end |
Instance Method Details
#==(other) ⇒ Object
122 123 124 |
# File 'lib/energyplus/SchedulesCSV.rb', line 122 def ==(other) eql?(other) end |
#close_table(this_table) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/energyplus/SchedulesCSV.rb', line 97 def close_table(this_table) if @table.empty? @table = this_table else @table.each_index do |idx| @table[idx].concat(this_table[idx]) end end end |
#eql?(other) ⇒ Boolean
125 126 127 |
# File 'lib/energyplus/SchedulesCSV.rb', line 125 def eql?(other) other.is_a?(Schedule) && to_s == other.to_s end |
#hash ⇒ Object
119 120 121 |
# File 'lib/energyplus/SchedulesCSV.rb', line 119 def hash to_s.hash end |
#print_table ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/energyplus/SchedulesCSV.rb', line 107 def print_table puts @name puts @type @table.each_index do |idx| puts @table[idx].join(', ') end puts end |
#to_s ⇒ Object
116 117 118 |
# File 'lib/energyplus/SchedulesCSV.rb', line 116 def to_s @lines.join("\n") end |