Class: Eeml::JsonEnvironmentParserV100

Inherits:
Object
  • Object
show all
Includes:
Exceptions
Defined in:
lib/eeml/json_environment_parser_v100.rb

Overview

A parser for json environments based on the EEML 5 specification.

Instance Method Summary collapse

Instance Method Details

#make_environment_from_hash(env_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/eeml/json_environment_parser_v100.rb', line 6

def make_environment_from_hash(env_hash)
  env = Environment.new(:title => env_hash["title"],
                        :description => env_hash["description"],
                        :feed_url => env_hash["feed"],
                        :website => env_hash["website"],
                        :email => env_hash["email"],
                        :icon => env_hash["icon"],
                        :status => env_hash["status"],
                        :identifier => env_hash["id"],
                        :private => env_hash["private"].to_s == "true",
                        :publisher => env_hash["publisher"],
                        :creator => env_hash["creator"])

  env.updated = Time.gm(*ParseDate.parsedate(env_hash['updated'])) unless env_hash['updated'].nil?
  
  env.has_tag_element = !!env_hash['tags']
  env.tags = env_hash['tags'] unless env_hash['tags'].nil?

  env.location = buildLocation(env_hash)

  env.add_datastreams(buildDatastreams(env_hash))
  
  return env
end

#make_environment_from_json(json_str) ⇒ Object



31
32
33
34
# File 'lib/eeml/json_environment_parser_v100.rb', line 31

def make_environment_from_json(json_str)
  env_hash = JSON.parse(strip_content(json_str))
  return make_environment_from_hash(env_hash)
end