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:



630
631
632
# File 'lib/rtree.rb', line 630

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:



606
607
608
# File 'lib/rtree.rb', line 606

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

.json_read(io_arg) ⇒ RTree::Style

Create a new Style instance from JSON path or stream

Examples:

Read from file

style = RTree::Style.json_read('some.style')

Parameters:

  • io_arg (String|IO)

    a path or readable stream

Returns:



597
598
599
# File 'lib/rtree.rb', line 597

def json_read(io_arg)
  RTree::IOUtil.io_with_mode(io_arg, 'r') { |io| super(io) }
end