Class: Cryptopunks::DesignSeries
- Inherits:
-
Object
- Object
- Cryptopunks::DesignSeries
- Defined in:
- lib/cryptopunks/image.rb
Overview
todo/check:
find a better way to (auto?) include more designs?
Class Method Summary collapse
-
.build(dir) ⇒ Object
find a better name for class (just use Series?) - why? why not?.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #data ⇒ Object
-
#initialize(dir) ⇒ DesignSeries
constructor
A new instance of DesignSeries.
- #keys ⇒ Object
- #size ⇒ Object
-
#to_h ⇒ Object
todo/check: use to_hash() - why? why not?.
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 |
#data ⇒ Object
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 |
#keys ⇒ Object
38 |
# File 'lib/cryptopunks/image.rb', line 38 def keys() data.keys; end |
#size ⇒ Object
37 |
# File 'lib/cryptopunks/image.rb', line 37 def size() data.size; end |
#to_h ⇒ Object
todo/check: use to_hash() - why? why not?
39 |
# File 'lib/cryptopunks/image.rb', line 39 def to_h() data; end |