Class: Chem::CDX::CDXString

Inherits:
Object
  • Object
show all
Defined in:
lib/chem/db/cdx.rb

Constant Summary collapse

Style =
{
  0x00=>'plain',
  0x01=>'bold',
  0x02=>'italic',
  0x04=>'underline',
  0x08=>'outline',
  0x10=>'shadow',
  0x20=>'subscript',
  0x40=>'superscript',
  0x60=>'formula'
}

Instance Method Summary collapse

Constructor Details

#initializeCDXString

Returns a new instance of CDXString.



845
846
847
848
# File 'lib/chem/db/cdx.rb', line 845

def initialize
  @str = ''
  @style = []
end

Instance Method Details

#analyze(str) ⇒ Object



858
859
# File 'lib/chem/db/cdx.rb', line 858

def analyze str
end

#push_string(str) ⇒ Object



850
851
852
# File 'lib/chem/db/cdx.rb', line 850

def push_string str
  @str += str
end

#push_style(style) ⇒ Object



854
855
856
# File 'lib/chem/db/cdx.rb', line 854

def push_style style
  @style.push(style)
end

#stringObject



888
889
890
# File 'lib/chem/db/cdx.rb', line 888

def string
  @str
end

#to_binObject



880
881
882
883
884
885
886
# File 'lib/chem/db/cdx.rb', line 880

def to_bin
  bin = [@style.length].pack('v')
  @style.each do |style|
    bin += style.pack('v*')
  end
  bin + @str.to_a.pack('a*')
end

#to_sObject



861
862
863
# File 'lib/chem/db/cdx.rb', line 861

def to_s
  @str.gsub(/'/, ''')
end

#to_xmlObject



865
866
867
868
869
870
871
872
873
874
875
876
877
878
# File 'lib/chem/db/cdx.rb', line 865

def to_xml
  if @style.length == 0
    return "<s>%s</s>" % @str
  else
    ret = ''
    i = 0
    @style.each do |style|
      i += 1
      n = @style[i] ? @style[i][0] -1 : -1
      ret += "<s font=\"%d\" size=\"%d\" face=\"%d\">%s</s>" % [style[1], style[3] / 20, style[2], @str[style[0]..n].gsub(/'/, '&apos;')]
    end
    return ret
  end
end