Class: Acrosslite
- Inherits:
-
Object
- Object
- Acrosslite
- Defined in:
- lib/entry.rb,
lib/acrosslite.rb
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- VERSION =
'0.2.1'
- ACROSSLITE =
2
- ROWS =
44
- COLUMNS =
45
- SOLUTION =
52
- DEFAULT_OPTIONS =
{ :filepath => nil, :content => nil, }
Instance Attribute Summary collapse
-
#across ⇒ Object
readonly
Returns the value of attribute across.
-
#author ⇒ Object
Returns the value of attribute author.
-
#copyright ⇒ Object
Returns the value of attribute copyright.
-
#diagram ⇒ Object
readonly
Returns the value of attribute diagram.
-
#down ⇒ Object
readonly
Returns the value of attribute down.
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
-
#solution ⇒ Object
readonly
Returns the value of attribute solution.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #area ⇒ Object
- #columns ⇒ Object
- #content ⇒ Object
-
#initialize(*args) ⇒ Acrosslite
constructor
A new instance of Acrosslite.
-
#read_puzzle(filepath = nil) ⇒ Object
If a filehandle or filepath were provided, open reads in the file’s contents into the content attribute which is then used for parsing.
- #rows ⇒ Object
Constructor Details
#initialize(*args) ⇒ Acrosslite
Returns a new instance of Acrosslite.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/acrosslite.rb', line 21 def initialize(*args) opts = {} case when args.length == 0 then when args.length == 1 && args[0].class == Hash then arg = args.shift if arg.class == Hash opts = arg end else raise ArgumentError, "new() expects hash or hashref as argument" end opts = DEFAULT_OPTIONS.merge opts @filepath = opts[:filepath] @content = opts[:content] || content @content_io = StringIO.new @content @across = Array.new @down = Array.new @layout = Array.new @solution = Array.new @diagram = Array.new end |
Instance Attribute Details
#across ⇒ Object (readonly)
Returns the value of attribute across.
7 8 9 |
# File 'lib/acrosslite.rb', line 7 def across @across end |
#author ⇒ Object
Returns the value of attribute author.
6 7 8 |
# File 'lib/acrosslite.rb', line 6 def @author end |
#copyright ⇒ Object
Returns the value of attribute copyright.
6 7 8 |
# File 'lib/acrosslite.rb', line 6 def copyright @copyright end |
#diagram ⇒ Object (readonly)
Returns the value of attribute diagram.
7 8 9 |
# File 'lib/acrosslite.rb', line 7 def diagram @diagram end |
#down ⇒ Object (readonly)
Returns the value of attribute down.
7 8 9 |
# File 'lib/acrosslite.rb', line 7 def down @down end |
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
7 8 9 |
# File 'lib/acrosslite.rb', line 7 def filepath @filepath end |
#solution ⇒ Object (readonly)
Returns the value of attribute solution.
7 8 9 |
# File 'lib/acrosslite.rb', line 7 def solution @solution end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/acrosslite.rb', line 6 def title @title end |
Instance Method Details
#area ⇒ Object
97 98 99 |
# File 'lib/acrosslite.rb', line 97 def area rows * columns end |
#columns ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/acrosslite.rb', line 62 def columns unless @columns @content_io.seek(COLUMNS) @columns = @content_io.read(1).unpack('C').first end @columns end |
#content ⇒ Object
50 51 52 |
# File 'lib/acrosslite.rb', line 50 def content @content ||= read_puzzle end |
#read_puzzle(filepath = nil) ⇒ Object
If a filehandle or filepath were provided, open reads in the file’s contents into the content attribute which is then used for parsing.
open must be called prior to parsing if content has not already been provided.
148 149 150 151 152 |
# File 'lib/acrosslite.rb', line 148 def read_puzzle(filepath=nil) filepath ||= @filepath raise unless filepath @content = open(@filepath).read end |
#rows ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/acrosslite.rb', line 54 def rows unless @rows @content_io.seek(ROWS) @rows = @content_io.read(1).unpack('C').first end @rows end |