Module: Card::Chunk

Defined in:
lib/card/chunk.rb

Defined Under Namespace

Classes: Abstract

Class Method Summary collapse

Class Method Details

.find_class_by_prefix(prefix) ⇒ Object



27
28
29
30
31
# File 'lib/card/chunk.rb', line 27

def find_class_by_prefix prefix
  config = prefix_map[ prefix[0,1] ] || prefix_map[ prefix[-1,1] ] || prefix_map[:default]
  #prefix identified by first character, last character, or default.  a little ugly...
  config[:class]
end

.get_prefix_regexp(chunk_list_key) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/card/chunk.rb', line 33

def get_prefix_regexp chunk_list_key
  prefix_regexp_by_list[chunk_list_key] ||= begin
    chunk_types = raw_list[chunk_list_key].map { |chunkname| const_get chunkname }
    prefix_res = chunk_types.map do |chunk_class|
      chunk_class.config[:prefix_re]
    end
    /(?:#{ prefix_res * '|' })/m
  end
end

.register_class(klass, hash) ⇒ Object



17
18
19
20
21
# File 'lib/card/chunk.rb', line 17

def register_class klass, hash
  klass.config = hash.merge :class => klass
  prefix_index = hash[:idx_char] || :default  # this is gross and needs to be moved out.  
  prefix_map[prefix_index] = klass.config
end

.register_list(key, list) ⇒ Object



23
24
25
# File 'lib/card/chunk.rb', line 23

def register_list key, list
  raw_list[key] = list
end