Class: Passcard::Outputter
- Inherits:
-
Object
- Object
- Passcard::Outputter
- Defined in:
- lib/passcard/outputter.rb
Direct Known Subclasses
Constant Summary collapse
- HEADERS =
50
'ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 αβγδθλμπϕ $£¥€¢' + # 50 '! # % & * < = > ? @ ✓ ∞ ♬ ♡ ♢ ♤ ♧ ☯ ☾ ✈ ☎ ☀ ☁ ☂ ☃ ★ ⌘ ♞ ✂ ✎ '
Instance Attribute Summary collapse
-
#grid ⇒ Object
30.
-
#palette ⇒ Object
30.
-
#reader ⇒ Object
30.
Class Method Summary collapse
-
.register(*args) ⇒ Object
Register one or more handler methods with this outputter.
Instance Method Summary collapse
- #col_headers ⇒ Object
- #data_in(file) ⇒ Object
- #get_grid(options = {}) ⇒ Object
-
#initialize(reader) ⇒ Outputter
constructor
A new instance of Outputter.
- #row_headers ⇒ Object
- #use_palette(type, options = {}) ⇒ Object
Constructor Details
#initialize(reader) ⇒ Outputter
Returns a new instance of Outputter.
8 9 10 11 |
# File 'lib/passcard/outputter.rb', line 8 def initialize(reader) self.reader = reader self.palette = Passcard::Palette.new end |
Instance Attribute Details
#grid ⇒ Object
30
6 7 8 |
# File 'lib/passcard/outputter.rb', line 6 def grid @grid end |
#palette ⇒ Object
30
6 7 8 |
# File 'lib/passcard/outputter.rb', line 6 def palette @palette end |
#reader ⇒ Object
30
6 7 8 |
# File 'lib/passcard/outputter.rb', line 6 def reader @reader end |
Class Method Details
.register(*args) ⇒ Object
Register one or more handler methods with this outputter. Passcard will then be able to use these methods to get the output from the outputter. For example, if you have an HtmlOutputter, you could do:
register :to_html, :to_xml
You could then do a Passcard.to_png and get the result of that method. The class which registers the method will receive the generator instance as the only argument, and the default implementation of initialize puts that into the passcard
accessor.
You can also have different method names in the outputter by providing a hash:
register to_html: :create_html, to_xml: :create_xml
30 31 32 33 34 35 36 37 |
# File 'lib/passcard/outputter.rb', line 30 def self.register(*args) hash = args.last.is_a?(Hash) ? args.pop : {} raise Passcard::Error, "You must register a method name!" if args.empty? && hash.empty? args.each{|name| hash[name] = name} hash.each do |name, method_name| ::Passcard.register_outputter(name, self, method_name) end end |
Instance Method Details
#col_headers ⇒ Object
51 52 53 54 55 |
# File 'lib/passcard/outputter.rb', line 51 def col_headers headers = self.class.const_get("COLUMN_HEADERS") rescue nil headers ||= self.class.const_get("HEADERS") headers.gsub(/ /, '').chars.take(grid.col_size) end |
#data_in(file) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/passcard/outputter.rb', line 66 def data_in(file) content = File.read(file) regex = /^\s*__END__\s*$/ return "" if content.match(regex).nil? content.split(regex).last.strip end |
#get_grid(options = {}) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/passcard/outputter.rb', line 57 def get_grid( = {}) random = [:type].to_s.to_sym == :random coordinates = get_grid_coordinates() @grid = reader.random_grid(20, 30) if random @grid = reader.slice(*coordinates) if !random use_palette :passcard @grid end |
#row_headers ⇒ Object
45 46 47 48 49 |
# File 'lib/passcard/outputter.rb', line 45 def row_headers headers = self.class.const_get("ROW_HEADERS") rescue nil headers ||= self.class.const_get("HEADERS") headers.gsub(/ /, '').chars.take(grid.row_size) end |
#use_palette(type, options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/passcard/outputter.rb', line 39 def use_palette(type, = {}) .merge!("n" => @grid.row_size) if @grid self.palette.type = type self.palette. = end |