Class: GatherContent::Config::Element::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/gather_content/config/elements/text.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#label, #microcopy, #name, #required

Instance Method Summary collapse

Methods inherited from Base

#to_json

Constructor Details

#initialize(name = "", required = false, label = "", microcopy = "", value = "", limit_type = :chars, limit = 0, plain_text = true) ⇒ Text



9
10
11
12
13
14
15
# File 'lib/gather_content/config/elements/text.rb', line 9

def initialize(name = "", required = false, label = "", microcopy = "", value = "", limit_type = :chars, limit = 0, plain_text = true)
  super(name, required, label, microcopy)
  @value = value
  @limit_type = limit_type
  @limit = limit
  @plain_text = plain_text
end

Instance Attribute Details

#limitObject

Returns the value of attribute limit.



7
8
9
# File 'lib/gather_content/config/elements/text.rb', line 7

def limit
  @limit
end

#limit_typeObject

Returns the value of attribute limit_type.



7
8
9
# File 'lib/gather_content/config/elements/text.rb', line 7

def limit_type
  @limit_type
end

#plain_textObject

Returns the value of attribute plain_text.



7
8
9
# File 'lib/gather_content/config/elements/text.rb', line 7

def plain_text
  @plain_text
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/gather_content/config/elements/text.rb', line 7

def value
  @value
end

Instance Method Details

#serialize(options = nil) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gather_content/config/elements/text.rb', line 17

def serialize(options = nil)
  raise ArgumentError, "limit_type is can only be :words or :chars" unless [ :words, :chars ].include?(limit_type)
  raise ArgumentError, "limit be a positive number" if limit.to_i < 0

  super.merge({
    type: 'text',
    value: value,
    limit_type: limit_type.to_s,
    limit: limit.to_i,
    plain_text: !!plain_text
  })
end