Class: Card::SetPattern
Direct Known Subclasses
Class Attribute Summary collapse
-
.anchor_parts_count ⇒ Object
Returns the value of attribute anchor_parts_count.
-
.anchorless ⇒ Object
Returns the value of attribute anchorless.
-
.assigns_type ⇒ Object
Returns the value of attribute assigns_type.
-
.junction_only ⇒ Object
Returns the value of attribute junction_only.
-
.pattern_code ⇒ Object
Returns the value of attribute pattern_code.
-
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
Class Method Summary collapse
- .anchorless? ⇒ Boolean
- .find(pattern_code) ⇒ Object
- .junction_only? ⇒ Boolean
- .new(card) ⇒ Object
- .pattern ⇒ Object
- .pattern_applies?(card) ⇒ Boolean
- .register(pattern_code, opts = {}) ⇒ Object
- .write_tmp_file(pattern_code, from_file, seq) ⇒ Object
Instance Method Summary collapse
- #anchor_codenames ⇒ Object
- #format_module_list(klass) ⇒ Object
-
#initialize(card) ⇒ SetPattern
constructor
Instance methods.
- #inspect ⇒ Object
- #lookup_module_list(modules_hash) ⇒ Object
- #module_key ⇒ Object
- #module_list ⇒ Object
- #pattern ⇒ Object
- #rule_set_key ⇒ Object
- #safe_key ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(card) ⇒ SetPattern
Instance methods
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/card/set_pattern.rb', line 73 def initialize card unless self.class.anchorless? @anchor_name = self.class.anchor_name(card).to_name @anchor_id = if self.class.respond_to? :anchor_id self.class.anchor_id card else Card.fetch_id @anchor_name end end self end |
Class Attribute Details
.anchor_parts_count ⇒ Object
Returns the value of attribute anchor_parts_count.
6 7 8 |
# File 'lib/card/set_pattern.rb', line 6 def anchor_parts_count @anchor_parts_count end |
.anchorless ⇒ Object
Returns the value of attribute anchorless.
6 7 8 |
# File 'lib/card/set_pattern.rb', line 6 def anchorless @anchorless end |
.assigns_type ⇒ Object
Returns the value of attribute assigns_type.
6 7 8 |
# File 'lib/card/set_pattern.rb', line 6 def assigns_type @assigns_type end |
.junction_only ⇒ Object
Returns the value of attribute junction_only.
6 7 8 |
# File 'lib/card/set_pattern.rb', line 6 def junction_only @junction_only end |
.pattern_code ⇒ Object
Returns the value of attribute pattern_code.
6 7 8 |
# File 'lib/card/set_pattern.rb', line 6 def pattern_code @pattern_code end |
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
6 7 8 |
# File 'lib/card/set_pattern.rb', line 6 def pattern_id @pattern_id end |
Class Method Details
.anchorless? ⇒ Boolean
16 17 18 |
# File 'lib/card/set_pattern.rb', line 16 def anchorless? !!anchorless end |
.find(pattern_code) ⇒ Object
8 9 10 |
# File 'lib/card/set_pattern.rb', line 8 def find pattern_code Card.set_patterns.find { |sub| sub.pattern_code == pattern_code } end |
.junction_only? ⇒ Boolean
12 13 14 |
# File 'lib/card/set_pattern.rb', line 12 def junction_only? !!junction_only end |
.new(card) ⇒ Object
20 21 22 |
# File 'lib/card/set_pattern.rb', line 20 def new card super if pattern_applies? card end |
.pattern ⇒ Object
24 25 26 |
# File 'lib/card/set_pattern.rb', line 24 def pattern Card.fetch(self.pattern_id, :skip_modules=>true).cardname end |
.pattern_applies?(card) ⇒ Boolean
39 40 41 |
# File 'lib/card/set_pattern.rb', line 39 def pattern_applies? card junction_only? ? card.cardname.junction? : true end |
.register(pattern_code, opts = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/card/set_pattern.rb', line 28 def register pattern_code, opts={} if self.pattern_id = Card::Codename[pattern_code] self.pattern_code = pattern_code Card.set_patterns.insert opts.delete(:index).to_i, self self.anchorless = !respond_to?( :anchor_name ) opts.each { |key, val| send "#{key}=", val } else warn "no codename for pattern_code #{pattern_code}" end end |
.write_tmp_file(pattern_code, from_file, seq) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/card/set_pattern.rb', line 47 def write_tmp_file pattern_code, from_file, seq to_file = "#{Card.paths['tmp/set_pattern'].first}/#{seq}-#{pattern_code}.rb" klass = "Card::#{pattern_code.camelize}Set" file_content = <<EOF # -*- encoding : utf-8 -*- class #{klass} < Card::SetPattern cattr_accessor :options class << self # ~~~~~~~~~~~ above autogenerated; below pulled from #{from_file} ~~~~~~~~~~~ #{ File.read from_file } # ~~~~~~~~~~~ below autogenerated; above pulled from #{from_file} ~~~~~~~~~~~ end register "#{pattern_code}", (options || {}) end EOF File.write to_file, file_content to_file end |
Instance Method Details
#anchor_codenames ⇒ Object
107 108 109 110 111 112 |
# File 'lib/card/set_pattern.rb', line 107 def anchor_codenames @anchor_name.parts.map do |part| part_id = Card.fetch_id part part_id && Card::Codename[ part_id.to_i ] or return nil end end |
#format_module_list(klass) ⇒ Object
103 104 105 |
# File 'lib/card/set_pattern.rb', line 103 def format_module_list klass hash = Card::Set.modules[ :nonbase_format ][ klass ] and lookup_module_list hash end |
#inspect ⇒ Object
122 123 124 |
# File 'lib/card/set_pattern.rb', line 122 def inspect "<#{self.class} #{to_s.to_name.inspect}>" end |
#lookup_module_list(modules_hash) ⇒ Object
95 96 97 |
# File 'lib/card/set_pattern.rb', line 95 def lookup_module_list modules_hash module_key && modules_hash[ module_key ] end |
#module_key ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/card/set_pattern.rb', line 85 def module_key (defined? @module_key) ? @module_key : @module_key = begin if self.class.anchorless? self.class.pattern_code.camelize elsif anchor_codenames "#{self.class.pattern_code.camelize}::#{anchor_codenames.map(&:to_s).map(&:camelize) * '::'}" end end end |
#module_list ⇒ Object
99 100 101 |
# File 'lib/card/set_pattern.rb', line 99 def module_list lookup_module_list Card::Set.modules[ :nonbase ] end |
#pattern ⇒ Object
114 115 116 |
# File 'lib/card/set_pattern.rb', line 114 def pattern @pattern ||= self.class.pattern end |
#rule_set_key ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/card/set_pattern.rb', line 131 def rule_set_key if self.class.anchorless? self.class.pattern_code elsif @anchor_id [ @anchor_id, self.class.pattern_code ].map( &:to_s ) * '+' end end |
#safe_key ⇒ Object
126 127 128 129 |
# File 'lib/card/set_pattern.rb', line 126 def safe_key caps_part = self.class.pattern_code.gsub(' ','_').upcase self.class.anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}" end |
#to_s ⇒ Object
118 119 120 |
# File 'lib/card/set_pattern.rb', line 118 def to_s self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}" end |