Class: DataField

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/data/data_field.rb

Overview

Contain data information for every field Params:

  • data - Data (Text). This is the field content

  • id - Identifier (Integer)

  • type - May be “text”, “textfile_path”, “textfile_url” or “image_url”

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, id, type) ⇒ DataField

initialize DataField



13
14
15
16
17
# File 'lib/asker/data/data_field.rb', line 13

def initialize(data, id, type)
  @data = data
  @id = id.to_i # TODO: revise where it comes from? Is it unique value?
  @type = type.to_sym
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/asker/data/data_field.rb', line 9

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/asker/data/data_field.rb', line 9

def type
  @type
end

Instance Method Details

#get(option = :raw) ⇒ Object

Return internal data rubocop:disable Metrics/MethodLength

Parameters:

  • option (Symbol) (defaults to: :raw)

Returns:

  • String



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/asker/data/data_field.rb', line 24

def get(option = :raw)
  case @type
  when :text
    return get_text(option)
  when :textfile_path
    return get_textfile_path(option)
  when :textfile_url
    return get_textfile_url(option)
  when :image_url
    return get_image_url(option)
  end
  raise ".get: data=#{@data}, type=#{@type}, option=#{option}"
end