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: 80, padding: 0, position: 0, separator: nil) ⇒ Object



62
63
64
65
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
# File 'lib/vv/array_methods.rb', line 62

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

  @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



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

def eighth
  self[7]
end

#fifthObject



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

def fifth
  self[4]
end

#format!(other) ⇒ Object



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

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

#fourthObject



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

def fourth
  self[3]
end

#ninthObject



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

def ninth
  self[8]
end

#secondObject



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

def second
  self[1]
end

#seventhObject



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

def seventh
  self[6]
end

#sixthObject



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

def sixth
  self[5]
end

#spacedObject



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

def spaced
  self.join(" ")
end

#tenthObject



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

def tenth
  self[9]
end

#thirdObject



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

def third
  self[2]
end