Module: VV::ArrayMethods

Included in:
Array
Defined in:
lib/vv/array_methods.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/vv/array_methods.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
  base.include(VV::SetMethods::SetAndArrayMethods)
  base.attr_accessor :cli_print_separator
end

Instance Method Details

#cli_print(width: nil, padding: nil, position: nil, separator: nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/vv/array_methods.rb', line 66

def cli_print width: nil,
              padding: nil,
              position: nil,
              separator: nil

  width    ||= 80
  padding  ||= 0
  position ||= 0

  @cli_print_separator ||= String.space
  separator ||= @cli_print_separator

  pad_length = padding - position
  position += pad_length
  print pad_length.spaces

  separator_required = false
  self.each do | elem |
    printable = String.capture_stdout {
      elem.cli_print width: width,
                     padding: padding,
                     position: position
    }
    string = printable.dup
    string.prepend separator if separator_required
    delta = string.unstyled.length

    if position + delta > width
      puts
      print padding.spaces
      print printable
      position = padding + printable.unstyled.length
    else
      print string
      position += delta
    end
    separator_required = true
  end
  position
end

#eighthObject



54
55
56
# File 'lib/vv/array_methods.rb', line 54

def eighth
  self[7]
end

#fifthObject



42
43
44
# File 'lib/vv/array_methods.rb', line 42

def fifth
  self[4]
end

#format!(other) ⇒ Object



26
27
28
# File 'lib/vv/array_methods.rb', line 26

def format!(other)
  self.spaced.format! other
end

#fourthObject



38
39
40
# File 'lib/vv/array_methods.rb', line 38

def fourth
  self[3]
end

#ninthObject



58
59
60
# File 'lib/vv/array_methods.rb', line 58

def ninth
  self[8]
end

#secondObject



30
31
32
# File 'lib/vv/array_methods.rb', line 30

def second
  self[1]
end

#seventhObject



50
51
52
# File 'lib/vv/array_methods.rb', line 50

def seventh
  self[6]
end

#sixthObject



46
47
48
# File 'lib/vv/array_methods.rb', line 46

def sixth
  self[5]
end

#spacedObject



22
23
24
# File 'lib/vv/array_methods.rb', line 22

def spaced
  self.join(" ")
end

#tenthObject



62
63
64
# File 'lib/vv/array_methods.rb', line 62

def tenth
  self[9]
end

#thirdObject



34
35
36
# File 'lib/vv/array_methods.rb', line 34

def third
  self[2]
end

#vv_jsonObject



18
19
20
# File 'lib/vv/array_methods.rb', line 18

def vv_json
  VV::JSON.generate self
end