Class: Zueribad::Application
- Inherits:
-
Object
- Object
- Zueribad::Application
- Defined in:
- lib/zueribad/application.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.run ⇒ Object
11 12 13 14 15 16 |
# File 'lib/zueribad/application.rb', line 11 def self.run app = Application.new app. app.baths app.output end |
Instance Method Details
#baths ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/zueribad/application.rb', line 18 def baths if @baths.nil? if .has_key?(:name) @baths = Bath.fetch([:name]) else @baths = Bath.fetch end end @baths end |
#max_lengths ⇒ Object
58 59 60 61 62 63 |
# File 'lib/zueribad/application.rb', line 58 def max_lengths { :name => baths.collect{ |x| x.name }.sort_by(&:length).last.length, :open_status => baths.collect{ |x| x.open_status }.sort_by(&:length).last.length } end |
#options ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/zueribad/application.rb', line 29 def if @options.nil? @options = {} OptionParser.new do |opts| opts. = "Usage: #{$0} [options]" opts.on("-n", "--name NAME", "Specify a bath name or any fragment of it") do |name| [:name] = name end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end.parse! end @options end |
#output ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/zueribad/application.rb', line 47 def output baths.each do |bath| puts "%-#{max_lengths[:name]}s | %-2s°C | %-#{max_lengths[:open_status]}s | %s" % [ bath.name, bath.temperature, bath.open_status, bath.modified_at ] end end |