Class: CommonChemistry::SearchResult

Inherits:
Object
  • Object
show all
Defined in:
lib/commonchemistry.rb

Overview

Represents an individual search result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ SearchResult

Returns a new instance of SearchResult.



111
112
113
114
115
# File 'lib/commonchemistry.rb', line 111

def initialize(data)
  @rn = data['rn']
  @name = data['name']
  @image = data['image']
end

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



109
110
111
# File 'lib/commonchemistry.rb', line 109

def image
  @image
end

#nameObject (readonly)

Returns the value of attribute name.



109
110
111
# File 'lib/commonchemistry.rb', line 109

def name
  @name
end

#rnObject (readonly)

Returns the value of attribute rn.



109
110
111
# File 'lib/commonchemistry.rb', line 109

def rn
  @rn
end

Instance Method Details

#save_image(filename) ⇒ Object

Saves the SVG image to a file

Parameters:

  • filename (String)

    The filename to save the image as



120
121
122
# File 'lib/commonchemistry.rb', line 120

def save_image(filename)
  File.open(filename, 'w') { |file| file.write(@image) }
end