Class: Eeml::Environment
Overview
This class represents the main point of entry to this library. In general we will be creating instances of this class, either by manually specifying the parameters, or probably more commonly, by passing in either an EEML or JSON formatted string which will be parsed to initialize the object.
Instance Attribute Summary collapse
-
#creator ⇒ Object
Returns the value of attribute creator.
-
#csv_version ⇒ Object
Returns the value of attribute csv_version.
-
#datastreams ⇒ Object
Returns the value of attribute datastreams.
-
#description ⇒ Object
Returns the value of attribute description.
-
#email ⇒ Object
Returns the value of attribute email.
-
#feed_url ⇒ Object
Returns the value of attribute feed_url.
-
#has_tag_element ⇒ Object
Returns the value of attribute has_tag_element.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#location ⇒ Object
Returns the value of attribute location.
-
#private ⇒ Object
Returns the value of attribute private.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated ⇒ Object
Returns the value of attribute updated.
-
#website ⇒ Object
Returns the value of attribute website.
Class Method Summary collapse
-
.new_from_csv(csv_str, version = nil) ⇒ Object
Create a new Environment object from a CSV string.
-
.new_from_eeml(xml_str) ⇒ Object
Create a new Environment object from an EEML string.
-
.new_from_json(json_str) ⇒ Object
Create a new Environment object from a JSON string.
-
.new_list_from_eeml(xml_str) ⇒ Object
Create multiple Environment objects from an EEML string containing multiple ‘environment` stanzas.
Instance Method Summary collapse
- #add_datastream(datastream) ⇒ Object
- #add_datastreams(array) ⇒ Object
-
#initialize(options = {}) ⇒ Environment
constructor
Create a new Environment object by passing parameters in a hash (just like creating an ActiveRecord object).
- #remove_last_datastream ⇒ Object
- #update_datastreams_from_csv_values!(csv_values) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Environment
Create a new Environment object by passing parameters in a hash (just like creating an ActiveRecord object)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/eeml/environment.rb', line 112 def initialize( = {}) @datastreams = [] @identifier = [:identifier] @creator = [:creator] @title = [:title] @status = [:status] @feed_url = [:feed_url] @description = [:description] @website = [:website] @email = [:email] @icon = [:icon] @private = [:private] @csv_version = [:csv_version] @publisher = [:publisher] @tags = [] @has_tag_element = false end |
Instance Attribute Details
#creator ⇒ Object
Returns the value of attribute creator.
102 103 104 |
# File 'lib/eeml/environment.rb', line 102 def creator @creator end |
#csv_version ⇒ Object
Returns the value of attribute csv_version.
105 106 107 |
# File 'lib/eeml/environment.rb', line 105 def csv_version @csv_version end |
#datastreams ⇒ Object
Returns the value of attribute datastreams.
106 107 108 |
# File 'lib/eeml/environment.rb', line 106 def datastreams @datastreams end |
#description ⇒ Object
Returns the value of attribute description.
103 104 105 |
# File 'lib/eeml/environment.rb', line 103 def description @description end |
#email ⇒ Object
Returns the value of attribute email.
103 104 105 |
# File 'lib/eeml/environment.rb', line 103 def email @email end |
#feed_url ⇒ Object
Returns the value of attribute feed_url.
103 104 105 |
# File 'lib/eeml/environment.rb', line 103 def feed_url @feed_url end |
#has_tag_element ⇒ Object
Returns the value of attribute has_tag_element.
107 108 109 |
# File 'lib/eeml/environment.rb', line 107 def has_tag_element @has_tag_element end |
#icon ⇒ Object
Returns the value of attribute icon.
103 104 105 |
# File 'lib/eeml/environment.rb', line 103 def icon @icon end |
#identifier ⇒ Object
Returns the value of attribute identifier.
102 103 104 |
# File 'lib/eeml/environment.rb', line 102 def identifier @identifier end |
#location ⇒ Object
Returns the value of attribute location.
104 105 106 |
# File 'lib/eeml/environment.rb', line 104 def location @location end |
#private ⇒ Object
Returns the value of attribute private.
108 109 110 |
# File 'lib/eeml/environment.rb', line 108 def private @private end |
#publisher ⇒ Object
Returns the value of attribute publisher.
102 103 104 |
# File 'lib/eeml/environment.rb', line 102 def publisher @publisher end |
#status ⇒ Object
Returns the value of attribute status.
103 104 105 |
# File 'lib/eeml/environment.rb', line 103 def status @status end |
#tags ⇒ Object
Returns the value of attribute tags.
107 108 109 |
# File 'lib/eeml/environment.rb', line 107 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
103 104 105 |
# File 'lib/eeml/environment.rb', line 103 def title @title end |
#updated ⇒ Object
Returns the value of attribute updated.
102 103 104 |
# File 'lib/eeml/environment.rb', line 102 def updated @updated end |
#website ⇒ Object
Returns the value of attribute website.
103 104 105 |
# File 'lib/eeml/environment.rb', line 103 def website @website end |
Class Method Details
.new_from_csv(csv_str, version = nil) ⇒ Object
Create a new Environment object from a CSV string
162 163 164 |
# File 'lib/eeml/environment.rb', line 162 def self.new_from_csv(csv_str, version = nil) EnvironmentBuilder.build_from_csv(csv_str, detect_csv_version(version, csv_str)) end |
.new_from_eeml(xml_str) ⇒ Object
Create a new Environment object from an EEML string.
152 153 154 |
# File 'lib/eeml/environment.rb', line 152 def self.new_from_eeml(xml_str) EnvironmentBuilder.build_from_xml(xml_str) end |
.new_from_json(json_str) ⇒ Object
Create a new Environment object from a JSON string.
157 158 159 |
# File 'lib/eeml/environment.rb', line 157 def self.new_from_json(json_str) EnvironmentBuilder.build_from_json(json_str) end |
.new_list_from_eeml(xml_str) ⇒ Object
Create multiple Environment objects from an EEML string containing multiple ‘environment` stanzas.
147 148 149 |
# File 'lib/eeml/environment.rb', line 147 def self.new_list_from_eeml(xml_str) EnvironmentBuilder.build_list_from_xml(xml_str) end |
Instance Method Details
#add_datastream(datastream) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/eeml/environment.rb', line 130 def add_datastream(datastream) #TODO: consider checking for unique identifier datastreams << datastream if dups = datastreams.map(&:identifier).compact.uniq! raise Eeml::Exceptions::DuplicateDataStreams, "Duplicate Datastream IDs: #{dups.join(', ')}" end end |
#add_datastreams(array) ⇒ Object
138 139 140 |
# File 'lib/eeml/environment.rb', line 138 def add_datastreams(array) array.each { |d| add_datastream d } end |
#remove_last_datastream ⇒ Object
142 143 144 |
# File 'lib/eeml/environment.rb', line 142 def remove_last_datastream datastreams.pop end |
#update_datastreams_from_csv_values!(csv_values) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/eeml/environment.rb', line 166 def update_datastreams_from_csv_values!(csv_values) csv_values.each_with_index do |new_val, index| datastream = datastreams[index] #if we don't have an existing datastream at same index, create new one if datastream.nil? datastream = DataStream.new(:identifier => index, :ordering => index) datastream.add_value(Value.new(:value => new_val)) self.datastreams << datastream else #we had a match, so update the existing datastream datastream.values.last.value = new_val end end # if the csv specifies FEWER feeds than the env currently has. if csv_values.size < self.datastreams.size # remove the excess from the end of the env's list. num_extra = datastreams.size - csv_values.size 1.upto(num_extra) { remove_last_datastream } end end |