Class: RTree::Style

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

Overview

A Ruby wrapper around RTree styles, used in PostScript plotting. in particular by #postscript.

Author:

  • RTree::Style J. J. Green

Class Method Summary collapse

Class Method Details

.from_a(array) ⇒ RTree::Style Also known as: from_array

Create a new Style instance from array of Hash

Examples:

Create a simple one-level style:

style = RTree::Style.from_a(
  [
    {
      fill: {
        rgb: [0.5, 0.5, 0.5]
      },
      stroke: {
        rgb: [0, 0, 1],
        width: 3
      }
    }
  ]
)

Parameters:

  • array (Array)

    an array of hash, this will be converted to JSON and read by .from_json

Returns:

See Also:


573
574
575
# File 'lib/rtree.rb', line 573

def from_a(array)
  from_json(array.to_json)
end

.from_json(json) ⇒ RTree::Style

Create a new Style instance from JSON string

Parameters:

  • json (String)

    a JSON string

Returns:

See Also:


549
550
551
# File 'lib/rtree.rb', line 549

def from_json(json)
  deserialise(json, Encoding::UTF_8) { |io| json_read(io) }
end

.json_read(io) ⇒ RTree::Style

Create a new Style instance from JSON stream

Examples:

Read from file

style = File.open('some.style', 'r') do |io|
  RTree::Style.json_read(io)
end

Parameters:

  • io (IO)

    a readable stream object

Returns:


540
541
542
# File 'lib/rtree.rb', line 540

def json_read(io)
  super
end