Class: ShareWith::ServiceDataType::StringList
- Inherits:
-
BasicDataType
- Object
- BasicDataType
- ShareWith::ServiceDataType::StringList
- Defined in:
- lib/share_with/service_data.rb
Overview
Define a list of string type.
Instance Attribute Summary
Attributes inherited from BasicDataType
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(val) ⇒ Object
-
#initialize(data) ⇒ StringList
constructor
A new instance of StringList.
- #reset! ⇒ Object
- #value ⇒ Object
- #value=(val) ⇒ Object
Methods inherited from BasicDataType
Constructor Details
#initialize(data) ⇒ StringList
Returns a new instance of StringList.
59 60 61 62 63 64 |
# File 'lib/share_with/service_data.rb', line 59 def initialize(data) super @value = [] @separator = data[:separator] || "," reset! end |
Instance Method Details
#clear ⇒ Object
85 86 87 |
# File 'lib/share_with/service_data.rb', line 85 def clear @value.clear end |
#delete(val) ⇒ Object
81 82 83 |
# File 'lib/share_with/service_data.rb', line 81 def delete(val) @value.delete val end |
#reset! ⇒ Object
89 90 91 92 |
# File 'lib/share_with/service_data.rb', line 89 def reset! clear @value = @default.instance_of?(String) ? @default.split(@separator).map(&:trim) : @default.clone end |
#value ⇒ Object
66 67 68 |
# File 'lib/share_with/service_data.rb', line 66 def value @value.to_text_list @separator end |
#value=(val) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/share_with/service_data.rb', line 70 def value=(val) val = val.split(@separator) if val.instance_of?(String) val = "" if val.nil? if val.empty? clear else @value.concat val end end |