Class: Item

Inherits:
Object
  • Object
show all
Defined in:
lib/script_storage_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ Item

Returns a new instance of Item.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/script_storage_item.rb', line 5

def initialize(key, value)
	case value.class.to_s.downcase
	when 'array'
		@value = []
		
		value.each do |v|
			@value.append(v)
		end
	else
		@value = value
	end

   @key = key
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/script_storage_item.rb', line 3

def key
  @key
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/script_storage_item.rb', line 3

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/script_storage_item.rb', line 33

def ==(other)
	if other.class == String
		@key == other
	else
		@key == other.key
	end
end

#showObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/script_storage_item.rb', line 20

def show
   type = @value.class.to_s.downcase
   
	case type
	when 'string'
		"#{key}: #{value}"
	when 'array'
		"#{key}(#{type}): #{@value.join(', ')}"
	else	
		"#{key}(#{type}): #{value}"
	end
end