Class: Newsmlg2::CatalogStore
- Inherits:
-
Object
- Object
- Newsmlg2::CatalogStore
- Includes:
- Enumerable
- Defined in:
- lib/newsmlg2/catalog_store.rb
Overview
The set of catalogs known to one NewsML-G2 document: inline
Instance Attribute Summary collapse
-
#catalogs ⇒ Object
readonly
Returns the value of attribute catalogs.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add_catalog(catalog) ⇒ Object (also: #<<)
- #add_catalog_ref(href) ⇒ Object
- #each ⇒ Object
- #get_scheme_for_alias(alias_name) ⇒ Object
- #get_scheme_for_uri(uri) ⇒ Object
-
#initialize ⇒ CatalogStore
constructor
A new instance of CatalogStore.
- #length ⇒ Object (also: #size)
- #schemes ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ CatalogStore
Returns a new instance of CatalogStore.
11 12 13 |
# File 'lib/newsmlg2/catalog_store.rb', line 11 def initialize @catalogs = [] end |
Instance Attribute Details
#catalogs ⇒ Object (readonly)
Returns the value of attribute catalogs.
15 16 17 |
# File 'lib/newsmlg2/catalog_store.rb', line 15 def catalogs @catalogs end |
Instance Method Details
#[](index) ⇒ Object
37 38 39 |
# File 'lib/newsmlg2/catalog_store.rb', line 37 def [](index) catalogs[index] end |
#add_catalog(catalog) ⇒ Object Also known as: <<
17 18 19 20 |
# File 'lib/newsmlg2/catalog_store.rb', line 17 def add_catalog(catalog) catalogs << catalog self end |
#add_catalog_ref(href) ⇒ Object
23 24 25 26 |
# File 'lib/newsmlg2/catalog_store.rb', line 23 def add_catalog_ref(href) catalog = Newsmlg2::CatalogCache.load(href) add_catalog(catalog) if catalog end |
#each ⇒ Object
28 29 30 |
# File 'lib/newsmlg2/catalog_store.rb', line 28 def each(&) catalogs.each(&) end |
#get_scheme_for_alias(alias_name) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/newsmlg2/catalog_store.rb', line 41 def get_scheme_for_alias(alias_name) schemes.each do |scheme| return scheme if scheme.alias_attr == alias_name end raise AliasNotFoundInCatalogs, 'no catalog of this document declares the scheme alias ' \ "'#{alias_name}'" end |
#get_scheme_for_uri(uri) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/newsmlg2/catalog_store.rb', line 50 def get_scheme_for_uri(uri) schemes.each do |scheme| return scheme if scheme.uri == uri end raise UriNotFoundInCatalogs, "no catalog of this document declares the scheme URI '#{uri}'" end |
#length ⇒ Object Also known as: size
32 33 34 |
# File 'lib/newsmlg2/catalog_store.rb', line 32 def length catalogs.length end |
#schemes ⇒ Object
58 59 60 |
# File 'lib/newsmlg2/catalog_store.rb', line 58 def schemes catalogs.flat_map(&:schemes) end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/newsmlg2/catalog_store.rb', line 62 def to_s "#<Newsmlg2::CatalogStore #{length} catalog(s)>" end |