Class: Cryptopunks::DesignSeries

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptopunks/image.rb

Overview

todo/check:

find a better way to (auto?) include more designs?

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ DesignSeries

Returns a new instance of DesignSeries.



27
28
29
# File 'lib/cryptopunks/image.rb', line 27

def initialize( dir )
  @dir = dir  # e.g. "#{Cryptopunks.root}/config/more"

end

Class Method Details

.build(dir) ⇒ Object

find a better name for class (just use Series?) - why? why not?



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cryptopunks/image.rb', line 14

def self.build( dir )
  data = {}
  paths =  Dir.glob( "#{dir}/**.txt" )
  paths.each do |path|
    basename = File.basename( path, File.extname( path ) )
    text = File.open( path, 'r:utf-8' ) { |f| f.read }
    ## todo/check: auto-parse "ahead of time" here

    ##              or keep "raw" text - why? why not?

    data[ basename ] = text
  end
  data
end

Instance Method Details

#[](key) ⇒ Object



36
# File 'lib/cryptopunks/image.rb', line 36

def [](key) data[ key ]; end

#dataObject



31
32
33
34
# File 'lib/cryptopunks/image.rb', line 31

def data
  ## note: lazy load / build on first demand only

  @data ||= self.class.build( @dir )
end

#keysObject



38
# File 'lib/cryptopunks/image.rb', line 38

def keys()    data.keys; end

#sizeObject



37
# File 'lib/cryptopunks/image.rb', line 37

def size()    data.size; end

#to_hObject

todo/check: use to_hash() - why? why not?



39
# File 'lib/cryptopunks/image.rb', line 39

def to_h()    data; end