Class: Oxidized::String

Inherits:
String
  • Object
show all
Defined in:
lib/oxidized/string.rb

Overview

Used in models, contains convenience methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = '') ⇒ String

Returns a new instance of String.



27
28
29
30
31
32
33
34
# File 'lib/oxidized/string.rb', line 27

def initialize(str = '')
  super
  return unless str.class == Oxidized::String

  @cmd  = str.cmd
  @name = str.name
  @type = str.type
end

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd.



4
5
6
# File 'lib/oxidized/string.rb', line 4

def cmd
  @cmd
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/oxidized/string.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/oxidized/string.rb', line 4

def type
  @type
end

Instance Method Details

#cut_both(head = 1, tail = 1) ⇒ Oxidized::String

Returns copy of self with first and last lines removed.

Returns:



17
18
19
# File 'lib/oxidized/string.rb', line 17

def cut_both(head = 1, tail = 1)
  Oxidized::String.new each_line.to_a[head..-1 - tail].join
end

#cut_head(lines = 1) ⇒ Oxidized::String

Returns copy of self with first line removed.

Returns:



12
13
14
# File 'lib/oxidized/string.rb', line 12

def cut_head(lines = 1)
  Oxidized::String.new each_line.to_a[lines..-1].join
end

#cut_tail(lines = 1) ⇒ Oxidized::String

Returns copy of self with last line removed.

Returns:



7
8
9
# File 'lib/oxidized/string.rb', line 7

def cut_tail(lines = 1)
  Oxidized::String.new each_line.to_a[0..-1 - lines].join
end

#set_cmd(command) ⇒ Object

sets @cmd and @name unless @name is already set



22
23
24
25
# File 'lib/oxidized/string.rb', line 22

def set_cmd(command)
  @cmd = command
  @name ||= @cmd.to_s.strip.gsub(/\s+/, '_') # what to do when command is proc? #to_s seems ghetto
end