Module: SEFAZ::Refinement::String

Defined in:
lib/sefaz/refinement.rb

Instance Method Summary collapse

Instance Method Details

#compress!Object



12
13
14
15
16
# File 'lib/sefaz/refinement.rb', line 12

def compress!
  doc = Nokogiri::XML::Document.parse(self, nil, "utf-8", Nokogiri::XML::ParseOptions::NOBLANKS)
  doc.search('*').each { |node| node.remove if node.content.strip.blank? }
  doc.canonicalize
end

#mask!(mask) ⇒ Object



18
19
20
21
# File 'lib/sefaz/refinement.rb', line 18

def mask!(mask)
  index = -1
  mask.gsub('#') { self[index += 1] }
end

#numeric?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/sefaz/refinement.rb', line 28

def numeric?
  self =~ /^(|-)?[0-9]+((\.|,)[0-9]+)?$/ ? true : false
end

#to_currency(options = {}) ⇒ Object



32
33
34
35
# File 'lib/sefaz/refinement.rb', line 32

def to_currency(options = {})
  return self.to_number.to_currency(options) if self.numeric?
  nil
end

#to_hash!Object



8
9
10
# File 'lib/sefaz/refinement.rb', line 8

def to_hash!
  Nori.new(convert_tags_to: lambda { |key| key.to_sym }).parse(self)
end

#to_number(options = {}) ⇒ Object



23
24
25
26
# File 'lib/sefaz/refinement.rb', line 23

def to_number(options={})
  return self.gsub(/,/, '.').to_f if self.numeric?
  nil
end