Class: AtCoderFriends::Problem::InputFormat
- Inherits:
-
Object
- Object
- AtCoderFriends::Problem::InputFormat
- Defined in:
- lib/at_coder_friends/problem.rb
Overview
holds information about input format
Constant Summary collapse
- ITEM_RANK =
{ number: 1, decimal: 2, string: 3 }.freeze
Instance Attribute Summary collapse
-
#cols ⇒ Object
Returns the value of attribute cols.
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#delim ⇒ Object
readonly
Returns the value of attribute delim.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #components ⇒ Object
-
#initialize(container: nil, item: nil, names: [], size: [], delim: '', cols: []) ⇒ InputFormat
constructor
A new instance of InputFormat.
- #item ⇒ Object
- #matrix_varray_components ⇒ Object
- #to_s ⇒ Object
- #varray_matrix_components ⇒ Object
- #vars ⇒ Object
Constructor Details
#initialize(container: nil, item: nil, names: [], size: [], delim: '', cols: []) ⇒ InputFormat
Returns a new instance of InputFormat.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/at_coder_friends/problem.rb', line 28 def initialize( container: nil, item: nil, names: [], size: [], delim: '', cols: [] ) @container = container @item = item @names = names @size = size @delim = delim @cols = cols end |
Instance Attribute Details
#cols ⇒ Object
Returns the value of attribute cols.
26 27 28 |
# File 'lib/at_coder_friends/problem.rb', line 26 def cols @cols end |
#container ⇒ Object (readonly)
Returns the value of attribute container.
25 26 27 |
# File 'lib/at_coder_friends/problem.rb', line 25 def container @container end |
#delim ⇒ Object (readonly)
Returns the value of attribute delim.
25 26 27 |
# File 'lib/at_coder_friends/problem.rb', line 25 def delim @delim end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
25 26 27 |
# File 'lib/at_coder_friends/problem.rb', line 25 def names @names end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
25 26 27 |
# File 'lib/at_coder_friends/problem.rb', line 25 def size @size end |
Instance Method Details
#components ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/at_coder_friends/problem.rb', line 61 def components @components ||= case container when :varray_matrix varray_matrix_components when :matrix_varray matrix_varray_components end end |
#item ⇒ Object
52 53 54 |
# File 'lib/at_coder_friends/problem.rb', line 52 def item @item || cols.max_by { |k| ITEM_RANK[k] } || :number end |
#matrix_varray_components ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/at_coder_friends/problem.rb', line 86 def matrix_varray_components [ self.class.new( container: :matrix, item: @item, names: names[0..0], size: size, delim: delim, cols: cols[0..0] ), self.class.new( container: :varray, names: names[1..], size: size[0..0], delim: delim, cols: cols[1..] || [] ) ] end |
#to_s ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/at_coder_friends/problem.rb', line 44 def to_s if container == :unknown "#{container} #{item}" else "#{container} #{item}(#{cols}) #{names} #{size} #{delim}" end end |
#varray_matrix_components ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/at_coder_friends/problem.rb', line 71 def varray_matrix_components [ self.class.new( container: :varray, names: names[0..-2], size: size[0..0], delim: delim, cols: cols[0..-2] ), self.class.new( container: :matrix, item: @item, names: names[-1..], size: size, delim: delim, cols: cols[-1..] || [] ) ] end |
#vars ⇒ Object
56 57 58 59 |
# File 'lib/at_coder_friends/problem.rb', line 56 def vars tmp = (@item && [@item]) || cols names.zip(tmp).map { |(name, col)| [name, col || :number] } end |