Class: Mensa::Client
- Inherits:
-
Object
- Object
- Mensa::Client
- Defined in:
- lib/mensa/client.rb
Instance Attribute Summary collapse
-
#canteens ⇒ Object
readonly
Returns the value of attribute canteens.
Instance Method Summary collapse
-
#initialize(stdout) ⇒ Client
constructor
A new instance of Client.
- #run ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(stdout) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mensa/client.rb', line 9 def initialize(stdout) @stdout = stdout @canteens = [] if File.exist?("#{ENV['HOME']}/.mensarc") load("#{ENV['HOME']}/.mensarc") elsif File.exist?(File.join(MENSA_DIR, 'config/canteens.rb')) load(File.join(MENSA_DIR, 'config/canteens.rb')) else raise RuntimeError, "No configuration found. Expected global configration in\n" << "#{File.join(MENSA_DIR, 'config/canteens.rb')}", caller end end |
Instance Attribute Details
#canteens ⇒ Object (readonly)
Returns the value of attribute canteens.
7 8 9 |
# File 'lib/mensa/client.rb', line 7 def canteens @canteens end |
Instance Method Details
#run ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/mensa/client.rb', line 28 def run to_s.lines.each_with_index do |line, index| stdout.write(line) end nil end |
#to_s ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mensa/client.rb', line 36 def to_s result = '' canteens.each do |canteen| result += print_header(canteen) if canteen.opened? result += canteen.fares.map { |f| print_fare(f) }.join(print_seperator) else result += print_state_closed end result += end result end |