Class: TokenCollection::Meta
- Inherits:
-
Object
- Object
- TokenCollection::Meta
- Defined in:
- lib/artbase/collection/token.rb
Overview
(nested) Meta classes
read data into struct
Class Method Summary collapse
Instance Method Summary collapse
-
#_blank(o) ⇒ Object
auto-convert “” (empty string) into nil.
-
#_normalize(str) ⇒ Object
“private” convenience / helper methods.
- #attributes ⇒ Object (also: #traits)
- #description ⇒ Object
-
#image ⇒ Object
(also: #image_url)
note: auto-convert “” (empty string) to nil.
-
#initialize(data) ⇒ Meta
constructor
A new instance of Meta.
- #name ⇒ Object
Constructor Details
#initialize(data) ⇒ Meta
Returns a new instance of Meta.
14 15 16 |
# File 'lib/artbase/collection/token.rb', line 14 def initialize( data ) @data = data end |
Class Method Details
.read(path) ⇒ Object
9 10 11 |
# File 'lib/artbase/collection/token.rb', line 9 def self.read( path ) new( read_json( path )) end |
Instance Method Details
#_blank(o) ⇒ Object
auto-convert “” (empty string) into nil
65 66 67 68 69 70 71 |
# File 'lib/artbase/collection/token.rb', line 65 def _blank( o ) ## auto-convert "" (empty string) into nil if o && o.strip.empty? nil else o end end |
#_normalize(str) ⇒ Object
“private” convenience / helper methods
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/artbase/collection/token.rb', line 53 def _normalize( str ) return if str.nil? ## check: check for nil - why? why not? ## normalize string ## remove leading and trailing spaces ## collapse two and more spaces into one ## change unicode space to ascii str = str.gsub( "\u{00a0}", ' ' ) str = str.strip.gsub( /[ ]{2,}/, ' ' ) str end |
#attributes ⇒ Object Also known as: traits
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/artbase/collection/token.rb', line 32 def attributes @attributes ||= begin traits = [] ## keep traits as (simple) ## ordered array of pairs for now ## ## in a step two make lookup via hash table ## or such easier / "automagic" @data[ 'attributes' ].each do |t| trait_type = t['trait_type'].strip trait_value = t['value'].strip traits << [trait_type, trait_value] end traits end end |
#description ⇒ Object
23 24 25 |
# File 'lib/artbase/collection/token.rb', line 23 def description @description ||= _normalize( @data['description'] ) end |
#image ⇒ Object Also known as: image_url
note: auto-convert “” (empty string) to nil
28 |
# File 'lib/artbase/collection/token.rb', line 28 def image() _blank( @data['image'] ); end |
#name ⇒ Object
19 20 21 |
# File 'lib/artbase/collection/token.rb', line 19 def name @name ||= _normalize( @data['name'] ) end |