Class: Pubid::Nist::Publisher
- Inherits:
-
Core::Entity
- Object
- Core::Entity
- Pubid::Nist::Publisher
- Defined in:
- lib/pubid/nist/publisher.rb
Instance Attribute Summary collapse
-
#publisher ⇒ Object
Returns the value of attribute publisher.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(publisher:) ⇒ Publisher
constructor
A new instance of Publisher.
- #to_s(format = :short) ⇒ Object
Constructor Details
#initialize(publisher:) ⇒ Publisher
Returns a new instance of Publisher.
8 9 10 11 12 |
# File 'lib/pubid/nist/publisher.rb', line 8 def initialize(publisher:) raise Errors::PublisherInvalidError, "#{publisher} is not valid publisher" unless PUBLISHERS["long"].key?(publisher) @publisher = publisher end |
Instance Attribute Details
#publisher ⇒ Object
Returns the value of attribute publisher.
6 7 8 |
# File 'lib/pubid/nist/publisher.rb', line 6 def publisher @publisher end |
Class Method Details
.parse(code) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pubid/nist/publisher.rb', line 24 def self.parse(code) publisher = /(#{PUBLISHERS["long"].keys.join('|')})/.match(code) return new(publisher: publisher.to_s) if publisher publisher = /(#{PUBLISHERS["long"].values.join('|')})(?=\.|\s)/.match(code) return new(publisher: PUBLISHERS["long"].key(publisher.to_s)) if publisher publisher = /(#{PUBLISHERS["abbrev"].values.join('|')})(?=\.|\s)/.match(code) return new(publisher: PUBLISHERS["abbrev"].key(publisher.to_s)) if publisher new(publisher: "NIST") end |
.publishers_keys ⇒ Object
20 21 22 |
# File 'lib/pubid/nist/publisher.rb', line 20 def self.publishers_keys PUBLISHERS["long"].keys end |
.regexp ⇒ Object
37 38 39 |
# File 'lib/pubid/nist/publisher.rb', line 37 def self.regexp /(#{PUBLISHERS["long"].keys.join('|')})(?=\.|\s)/ end |
Instance Method Details
#to_s(format = :short) ⇒ Object
14 15 16 17 18 |
# File 'lib/pubid/nist/publisher.rb', line 14 def to_s(format = :short) return @publisher if i[short mr].include?(format) PUBLISHERS[format.to_s][@publisher] end |