Class: Cmus::Controller::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/cmus/controller/status.rb

Defined Under Namespace

Classes: Song

Instance Attribute Summary collapse

Instance Method Summary collapse

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.tags.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

#controllerObject (readonly)

Returns the value of attribute controller.



35
36
37
# File 'lib/cmus/controller/status.rb', line 35

def controller
  @controller
end

#settingsObject (readonly)

Returns the value of attribute settings.



35
36
37
# File 'lib/cmus/controller/status.rb', line 35

def settings
  @settings
end

#songObject (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_symObject



101
102
103
# File 'lib/cmus/controller/status.rb', line 101

def to_sym
	@status
end

#volumeObject



93
94
95
# File 'lib/cmus/controller/status.rb', line 93

def volume
	(settings.vol_left + settings.vol_right) / 2.0
end