Class: TokenCollection::Meta

Inherits:
Object
  • Object
show all
Defined in:
lib/artbase/collection/token.rb

Overview

(nested) Meta classes

read meta data into struct

Class Method Summary collapse

Instance Method Summary collapse

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



69
70
71
72
73
74
75
# File 'lib/artbase/collection/token.rb', line 69

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



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/artbase/collection/token.rb', line 57

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

#attributesObject Also known as: traits



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/artbase/collection/token.rb', line 36

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

#descriptionObject



27
28
29
# File 'lib/artbase/collection/token.rb', line 27

def description
  @description ||= _normalize( @data['description'] )
end

#imageObject Also known as: image_url

note: auto-convert “” (empty string) to nil



32
# File 'lib/artbase/collection/token.rb', line 32

def image()          _blank( @data['image'] ); end

#nameObject



19
20
21
22
23
24
# File 'lib/artbase/collection/token.rb', line 19

def name
  ## note: name might be an integer number e.g. 0/1/2 etc.
  ##      e.g. see crypto pudgy punks and others?
  ##    always auto-convert to string
  @name ||= _normalize( @data['name'].to_s )
end