Class: Pakyow::Presenter::Attributes::Set
- Inherits:
-
Attribute
- Object
- Attribute
- Pakyow::Presenter::Attributes::Set
show all
- Extended by:
- Forwardable, Support::SafeStringHelpers
- Includes:
- Support::SafeStringHelpers
- Defined in:
- lib/pakyow/presenter/attributes/set.rb
Overview
Wraps the value for a set-type view attribute (e.g. class).
Behaves just like a normal Set
.
Constant Summary
collapse
- VALUE_SEPARATOR =
" ".freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Attribute
#==, #initialize, #initialize_copy
Class Method Details
permalink
.parse(value) ⇒ Object
[View source]
48
49
50
51
52
53
54
55
56
|
# File 'lib/pakyow/presenter/attributes/set.rb', line 48
def parse(value)
if value.is_a?(Array) || value.is_a?(::Set)
new(::Set.new(value.map { |v| ensure_html_safety(v) }))
elsif value.respond_to?(:to_s)
new(::Set.new(value.to_s.split(VALUE_SEPARATOR).map { |v| ensure_html_safety(v) }))
else
raise ArgumentError.new("expected value to be an Array, Set, or String")
end
end
|
Instance Method Details
permalink
#<<(value) ⇒ Object
[View source]
29
30
31
|
# File 'lib/pakyow/presenter/attributes/set.rb', line 29
def <<(value)
@value << ensure_html_safety(value)
end
|
permalink
#add(value) ⇒ Object
[View source]
33
34
35
|
# File 'lib/pakyow/presenter/attributes/set.rb', line 33
def add(value)
@value.add(ensure_html_safety(value))
end
|
permalink
#delete(value) ⇒ Object
[View source]
37
38
39
|
# File 'lib/pakyow/presenter/attributes/set.rb', line 37
def delete(value)
@value.delete(value.to_s)
end
|
[View source]
25
26
27
|
# File 'lib/pakyow/presenter/attributes/set.rb', line 25
def include?(value)
@value.include?(value.to_s)
end
|