Class: BlueStateDigital::DatasetMap
- Inherits:
-
ApiDataModel
- Object
- ApiDataModel
- BlueStateDigital::DatasetMap
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/blue_state_digital/dataset_map.rb
Constant Summary collapse
- UPLOAD_ENDPOINT =
'/cons/upload_dataset_map'- DELETE_ENDPOINT =
'/cons/delete_dataset_map'- FIELDS =
[ :map_id, :type ]
Constants inherited from ApiDataModel
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#data_header ⇒ Object
readonly
Returns the value of attribute data_header.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Attributes inherited from ApiDataModel
Class Method Summary collapse
Instance Method Summary collapse
- #add_data_header(header_row) ⇒ Object
- #add_data_row(row) ⇒ Object
- #delete ⇒ Object
-
#initialize(args = {}) ⇒ DatasetMap
constructor
A new instance of DatasetMap.
- #read_attribute_for_validation(attr) ⇒ Object
- #save ⇒ Object
Methods inherited from ApiDataModel
Constructor Details
#initialize(args = {}) ⇒ DatasetMap
Returns a new instance of DatasetMap.
19 20 21 22 23 24 |
# File 'lib/blue_state_digital/dataset_map.rb', line 19 def initialize(args={}) super @data = [] @data_header = nil @errors = ActiveModel::Errors.new(self) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
15 16 17 |
# File 'lib/blue_state_digital/dataset_map.rb', line 15 def data @data end |
#data_header ⇒ Object (readonly)
Returns the value of attribute data_header.
15 16 17 |
# File 'lib/blue_state_digital/dataset_map.rb', line 15 def data_header @data_header end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/blue_state_digital/dataset_map.rb', line 15 def errors @errors end |
Class Method Details
.human_attribute_name(attr, options = {}) ⇒ Object
90 91 92 |
# File 'lib/blue_state_digital/dataset_map.rb', line 90 def self.human_attribute_name(attr, = {}) attr end |
.lookup_ancestors ⇒ Object
93 94 95 |
# File 'lib/blue_state_digital/dataset_map.rb', line 93 def self.lookup_ancestors [self] end |
Instance Method Details
#add_data_header(header_row) ⇒ Object
34 35 36 |
# File 'lib/blue_state_digital/dataset_map.rb', line 34 def add_data_header(header_row) @data_header = header_row end |
#add_data_row(row) ⇒ Object
30 31 32 |
# File 'lib/blue_state_digital/dataset_map.rb', line 30 def add_data_row(row) @data.push row end |
#delete ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/blue_state_digital/dataset_map.rb', line 63 def delete if map_id.nil? errors.add(:map_id,"is missing") return false end if connection response = connection.perform_request_raw( DELETE_ENDPOINT, { api_ver: 2 }, "POST", {map_id: map_id}.to_json ) if(response.status==200) true else errors.add(:web_service,"#{response.body}") false end else errors.add(:connection,"is missing") false end end |
#read_attribute_for_validation(attr) ⇒ Object
87 88 89 |
# File 'lib/blue_state_digital/dataset_map.rb', line 87 def read_attribute_for_validation(attr) send(attr) end |
#save ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/blue_state_digital/dataset_map.rb', line 38 def save #errors.add(:data, "cannot be blank") if @data.blank? if valid? if connection response = connection.perform_request_raw( UPLOAD_ENDPOINT, { api_ver: 2, content_type: "text/csv", accept: 'application/json' }, "PUT", csv_payload ) if(response.status == 202) true else errors.add(:web_service,"#{response.body}") false end else errors.add(:connection,"is missing") false end else false end end |