Class: CF::InputFormat

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/cf/input_format.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options={})
  @station            = options[:station]
  @line               = options[:line]
  @name              = options[:name]
  @required           = options[:required]
  @valid_type  = options[:valid_type].nil? ? nil : options[: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.}/#{@line.title.downcase}/input_formats.json", :input_format => {:name => @name, :required => @required, :valid_type => @valid_type})
    else
      @resp = self.class.post("/lines/#{CF.}/#{@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

#errorsObject

Contains error message if any



21
22
23
# File 'lib/cf/input_format.rb', line 21

def errors
  @errors
end

#idObject

ID of an input_format



15
16
17
# File 'lib/cf/input_format.rb', line 15

def id
  @id
end

#line_titleObject

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

#nameObject

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

#requiredObject

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_typeObject

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.}/#{line.title.downcase}/input_formats.json")
end

Instance Method Details

#to_sObject

: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