Class: Chem::CDX::CDXString
- Inherits:
-
Object
- Object
- Chem::CDX::CDXString
- 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
- #analyze(str) ⇒ Object
-
#initialize ⇒ CDXString
constructor
A new instance of CDXString.
- #push_string(str) ⇒ Object
- #push_style(style) ⇒ Object
- #string ⇒ Object
- #to_bin ⇒ Object
- #to_s ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize ⇒ CDXString
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 |
#string ⇒ Object
888 889 890 |
# File 'lib/chem/db/cdx.rb', line 888 def string @str end |
#to_bin ⇒ Object
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_s ⇒ Object
861 862 863 |
# File 'lib/chem/db/cdx.rb', line 861 def to_s @str.gsub(/'/, ''') end |
#to_xml ⇒ Object
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(/'/, ''')] end return ret end end |