Class: CF::InputFormat
- Inherits:
-
Object
- Object
- CF::InputFormat
- Includes:
- Client
- Defined in:
- lib/cf/input_format.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Contains error message if any.
-
#id ⇒ Object
ID of an input_format.
-
#line_title ⇒ Object
Title of Line with which input_format is associated.
-
#name ⇒ Object
name for the input_format, e.g.
-
#required ⇒ Object
required boolean either true or false , e.g.
-
#valid_type ⇒ Object
valid_type format of the source for the input_format, e.g.
Class Method Summary collapse
-
.all(line) ⇒ Object
Returns all the input headers of a specific line ===Usage Example: line = CF::Line.new(“Digitize Card”,“Survey”).
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ InputFormat
constructor
Initializes a new input_format ===Usage Example: line = CF::Line.create(“Digitize”, “Survey”).
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}) ⇒ InputFormat
Initializes a new input_format
Usage Example:
line = CF::Line.create("Digitize", "Survey")
attrs =
{
:name => "image_url",
:required => true,
:valid_type => "url"
}
input_format = CF::InputFormat.new(attrs)
line.input_formats input_format
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cf/input_format.rb', line 36 def initialize(={}) @station = [:station] @line = [:line] @name = [:name] @required = [:required] @valid_type = [:valid_type].nil? ? nil : [:valid_type] if !@station.nil? or !@line.nil? line_title = @station.nil? ? @line.title : @station.line_title if @valid_type @resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/input_formats.json", :input_format => {:name => @name, :required => @required, :valid_type => @valid_type}) else @resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/input_formats.json", :input_format => {:name => @name, :required => @required}) end @resp.to_hash.each_pair do |k,v| self.send("#{k}=",v) if self.respond_to?(k) end self.errors = @resp['error']['message'] if @resp['code'] != 200 @line_title = line_title if !@station.nil? && @station.except.nil? && @station.extra.nil? @station.input_formats = self else @line.input_formats = self end end end |
Instance Attribute Details
#errors ⇒ Object
Contains error message if any
21 22 23 |
# File 'lib/cf/input_format.rb', line 21 def errors @errors end |
#id ⇒ Object
ID of an input_format
15 16 17 |
# File 'lib/cf/input_format.rb', line 15 def id @id end |
#line_title ⇒ Object
Title of Line with which input_format is associated
18 19 20 |
# File 'lib/cf/input_format.rb', line 18 def line_title @line_title end |
#name ⇒ Object
name for the input_format, e.g. :name => “image_url”
6 7 8 |
# File 'lib/cf/input_format.rb', line 6 def name @name end |
#required ⇒ Object
required boolean either true or false , e.g. :required => “true” & if false then you don’t need to mention
9 10 11 |
# File 'lib/cf/input_format.rb', line 9 def required @required end |
#valid_type ⇒ Object
valid_type format of the source for the input_format, e.g. :valid_type => “url”
12 13 14 |
# File 'lib/cf/input_format.rb', line 12 def valid_type @valid_type end |
Class Method Details
.all(line) ⇒ Object
Returns all the input headers of a specific line
Usage Example:
line = CF::Line.new("Digitize Card","Survey")
attrs_1 =
{
:name => "image_url",
:required => true,
:valid_type => "url"
}
attrs_2 =
{
:name => "text_url",
:required => true,
:valid_type => "url"
}
input_format_1 = CF::InputFormat.new(attrs_1)
line.input_formats input_format_1
input_format_2 = CF::InputFormat.new(attrs_2)
line.input_formats input_format_2
input_formats_of_line = CF::InputFormat.all(line)
returns an array of input headers associated with line
86 87 88 |
# File 'lib/cf/input_format.rb', line 86 def self.all(line) get("/lines/#{CF.account_name}/#{line.title.downcase}/input_formats.json") end |
Instance Method Details
#to_s ⇒ Object
:nodoc:
90 91 92 |
# File 'lib/cf/input_format.rb', line 90 def to_s # :nodoc: "{:id => #{self.id}, :name => #{self.name}, :required => #{self.required}, :valid_type => #{self.valid_type}, :errors => #{self.errors}}" end |