Class: Pubid::Nist::Publisher

Inherits:
Core::Entity
  • Object
show all
Defined in:
lib/pubid/nist/publisher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#publisherObject

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_keysObject



20
21
22
# File 'lib/pubid/nist/publisher.rb', line 20

def self.publishers_keys
  PUBLISHERS["long"].keys
end

.regexpObject



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