Class: PlateID
- Inherits:
-
Object
- Object
- PlateID
- Defined in:
- lib/plate_id.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #base_class ⇒ Object
- #find ⇒ Object
- #host ⇒ Object
- #id ⇒ Object
- #id=(id) ⇒ Object
-
#initialize(plate_id) ⇒ PlateID
constructor
A new instance of PlateID.
- #plate_class ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(plate_id) ⇒ PlateID
Returns a new instance of PlateID.
45 46 47 |
# File 'lib/plate_id.rb', line 45 def initialize(plate_id) @uri = fetch_uri(plate_id) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
23 24 25 |
# File 'lib/plate_id.rb', line 23 def uri @uri end |
Class Method Details
.create(model) ⇒ Object
6 7 8 9 |
# File 'lib/plate_id.rb', line 6 def create(model) uri = URI::PlateID.create(model) new(uri) if uri end |
.find(plate_id) ⇒ Object
17 18 19 20 |
# File 'lib/plate_id.rb', line 17 def find(plate_id) res = parse(plate_id) res&.find end |
.parse(plate_id) ⇒ Object
11 12 13 14 15 |
# File 'lib/plate_id.rb', line 11 def parse(plate_id) plate_id.is_a?(self) ? plate_id : new(plate_id) rescue URI::Error nil end |
Instance Method Details
#==(other) ⇒ Object
59 60 61 |
# File 'lib/plate_id.rb', line 59 def ==(other) to_s == other.to_s end |
#base_class ⇒ Object
29 30 31 |
# File 'lib/plate_id.rb', line 29 def base_class uri.base_class end |
#find ⇒ Object
53 54 55 56 57 |
# File 'lib/plate_id.rb', line 53 def find return unless uri.id plate_class&.find_by(id: uri.id) end |
#host ⇒ Object
25 26 27 |
# File 'lib/plate_id.rb', line 25 def host uri.host end |
#id ⇒ Object
33 34 35 |
# File 'lib/plate_id.rb', line 33 def id uri.id end |
#id=(id) ⇒ Object
37 38 39 |
# File 'lib/plate_id.rb', line 37 def id=(id) uri.id = id end |
#plate_class ⇒ Object
49 50 51 |
# File 'lib/plate_id.rb', line 49 def plate_class fetch_plate_class(uri)&.safe_constantize end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/plate_id.rb', line 41 def to_s uri.to_s end |