Class: Cmus::Controller::Status
- Inherits:
-
Object
- Object
- Cmus::Controller::Status
- Defined in:
- lib/cmus/controller/status.rb
Defined Under Namespace
Classes: Song
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#song ⇒ Object
readonly
Returns the value of attribute song.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(controller) ⇒ Status
constructor
A new instance of Status.
- #to_sym ⇒ Object
- #volume ⇒ Object
Constructor Details
#initialize(controller) ⇒ Status
Returns a new instance of Status.
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 |
# File 'lib/cmus/controller/status.rb', line 37 def initialize (controller) @controller = controller @song = Song.new(controller) @settings = OpenStruct.new controller.send 'status' controller.wait_for_data.each_line {|line| type, data = line.chomp.split ' ', 2 next unless type case type.to_sym when :status @status = case data.to_sym when :stopped then :STOP when :paused then :PAUSE else :PLAY end when :file @song.file = data when :duration @song.duration = data.to_i when :position @song.position = data.to_i when :tag name, data = data.split ' ', 2 @song..send "#{name}=", data when :set name, data = data.split ' ', 2 data = if data == 'false' false elsif data == 'true' true elsif (Integer(data) rescue false) data.to_i elsif (Float(data) rescue false) data.to_f else data end @settings.send "#{name}=", data end } @song = nil if self == :stop end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
35 36 37 |
# File 'lib/cmus/controller/status.rb', line 35 def controller @controller end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
35 36 37 |
# File 'lib/cmus/controller/status.rb', line 35 def settings @settings end |
#song ⇒ Object (readonly)
Returns the value of attribute song.
35 36 37 |
# File 'lib/cmus/controller/status.rb', line 35 def song @song end |
Instance Method Details
#==(other) ⇒ Object
97 98 99 |
# File 'lib/cmus/controller/status.rb', line 97 def == (other) super || to_sym.downcase == other.to_sym.downcase end |
#to_sym ⇒ Object
101 102 103 |
# File 'lib/cmus/controller/status.rb', line 101 def to_sym @status end |
#volume ⇒ Object
93 94 95 |
# File 'lib/cmus/controller/status.rb', line 93 def volume (settings.vol_left + settings.vol_right) / 2.0 end |