Class: Rubytypeformio::Field

Inherits:
Base
  • Object
show all
Defined in:
lib/rubytypeformio/field.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#compact, #pretty

Constructor Details

#initialize(question, description, required, type) ⇒ Field

Returns a new instance of Field.



9
10
11
12
13
14
# File 'lib/rubytypeformio/field.rb', line 9

def initialize (question, description, required, type)
  @description = description
  @question = question
  @required = required
  @type = type
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/rubytypeformio/field.rb', line 7

def description
  @description
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/rubytypeformio/field.rb', line 7

def id
  @id
end

#questionObject

Returns the value of attribute question.



7
8
9
# File 'lib/rubytypeformio/field.rb', line 7

def question
  @question
end

#requiredObject

Returns the value of attribute required.



7
8
9
# File 'lib/rubytypeformio/field.rb', line 7

def required
  @required
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/rubytypeformio/field.rb', line 7

def type
  @type
end

Class Method Details

.from_json(string) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rubytypeformio/field.rb', line 30

def self.from_json(string)
  data = JSON.load(string)
  obj = self.new( data["description"],
                  data["question"],
                  data["required"],
                  data["type"] )
  obj.id = data["id"]
  return obj
end

Instance Method Details

#to_hObject



20
21
22
23
24
25
26
27
28
# File 'lib/rubytypeformio/field.rb', line 20

def to_h
  hash = {
      :description => @description,
      :question => @question,
      :required => @required,
      :type => @type,
      :id => @id,
  }
end

#to_jsonObject



16
17
18
# File 'lib/rubytypeformio/field.rb', line 16

def to_json
  JSON.dump(self.to_h)
end