class Pastee::Paste::Section

Wrapper class for paste sections.

Attributes

contents[R]

@return [String] Contents of the section.

id[R]

@return [Integer] The ID for this section.

name[R]

@return [String] The name of the section.

size[R]

@return [Integer] Size of the section in bytes.

syntax[R]

@return [String] The short name of the syntax used in this section.

Public Class Methods

new(opts = {}) click to toggle source

Create a new Section object. Used when creating new pastes and when getting existing pastes. For creating new pastes, you only need to provide the name and contents and optionally syntax. The rest will be created automatically by the pastee API or by our {#to_h} method (syntax defaults to “autodetect”). ID and size are created by pastee, they are only here for receiving paste objects. @param opts [Hash] Options hash. Keys can either be strings or symbols — they will be converted to symbols. @option opts [Integer] :id Section ID. @option opts [String] :syntax The syntax short name for this section. @option opts [String] :name The name of this section. @option opts [String] :contents The contents of this section. @option opts [Integer] :size The size of this section.

# File lib/pastee/paste.rb, line 99
def initialize(opts = {})
  # Standardize keys so that both the pastee API (which uses strings) and pastee-rb consumers (who use symbols) can
  # both use this method.
  opts = Hash[opts.map { |k, v| [k.to_sym, v] }]

  @id = opts[:id]
  @syntax = opts[:syntax]
  @name = opts[:name]
  @contents = opts[:contents]
  @size = opts[:size]
end

Public Instance Methods

to_h() click to toggle source

Converts this to a hash object. Used in submitting pastes. @return [Hash]

# File lib/pastee/paste.rb, line 113
def to_h
  hash = {
    name: name,
    contents: contents
  }
  hash[:id] = id if id
  hash[:syntax] = syntax || 'autodetect'
  hash[:size] = size if size

  hash
end