Class: Mooncats::DesignSeries
- Inherits:
-
Object
- Object
- Mooncats::DesignSeries
- Defined in:
- lib/mooncats/design.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 - why? why not?.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #data ⇒ Object
-
#initialize(dir) ⇒ DesignSeries
constructor
A new instance of DesignSeries.
- #size ⇒ Object
Constructor Details
#initialize(dir) ⇒ DesignSeries
Returns a new instance of DesignSeries.
115 116 117 |
# File 'lib/mooncats/design.rb', line 115 def initialize( dir ) @dir = dir # e.g. "#{Mooncats.root}/config/v2" end |
Class Method Details
.build(dir) ⇒ Object
find a better name for class - why? why not?
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mooncats/design.rb', line 101 def self.build( dir ) data = {} paths = Dir.glob( "#{dir}/**.txt" ) paths.each do |path| basename = File.basename( path, File.extname( path ) ) num = basename.to_i( 10 ) ## use base 10 (e.g. 001 => 1, 002 => 2, etc.) 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[ num ] = text end data end |
Instance Method Details
#[](index) ⇒ Object
124 |
# File 'lib/mooncats/design.rb', line 124 def [](index) data[ index ]; end |
#data ⇒ Object
119 120 121 122 |
# File 'lib/mooncats/design.rb', line 119 def data ## note: lazy load / build on first demand only @data ||= self.class.build( @dir ) end |
#size ⇒ Object
125 |
# File 'lib/mooncats/design.rb', line 125 def size() data.size; end |