class ParaBlock
Public Class Methods
from_s(string)
click to toggle source
Type conversions
# File lib/bayeux/para_block.rb, line 127 def self.from_s(string) unless string =~ /\s+/ then header = string.split(':') if header[0].nil? then # If we can't work out the type, set everything # to null type = :none target = nil else # Attempt to coerce the content to a type block_type = header[0].to_sym unless block_type.nil? then type = block_type else type = :none end target = header[1] end else type = :none end return ParaBlock.new(type, "", target) end
json_create(json_hash)
click to toggle source
# File lib/bayeux/para_block.rb, line 190 def self.json_create(json_hash) begin require 'json' block = new(json_hash["type"], json_hash["content"], json_hash["target"]) return block rescue LoadError warn "The JSON gem couldn't be loaded, and so the JSON representation could not be generated" end end
new(type, content = "", target = nil)
click to toggle source
Default contructor
# File lib/bayeux/para_block.rb, line 4 def initialize(type, content = "", target = nil) @orig_type = type @type = normalise_type(type) @content = content @target = target end
Public Instance Methods
<<(value)
click to toggle source
Convenience functions
# File lib/bayeux/para_block.rb, line 41 def <<(value) @content << value end
clear()
click to toggle source
# File lib/bayeux/para_block.rb, line 49 def clear @content.clear end
content()
click to toggle source
# File lib/bayeux/para_block.rb, line 26 def content @content end
content=(content)
click to toggle source
# File lib/bayeux/para_block.rb, line 23 def content=(content) @content = content end
content_to_type!()
click to toggle source
Take the current contents as a block type, and reset the content
# File lib/bayeux/para_block.rb, line 69 def content_to_type! unless @content =~ /\s+/ then header = @content.split(':') if header[0].nil? then # If we can't work out the type, set everything # to null @type = :none @target = nil else # Attempt to coerce the content to a type block_type = header[0].to_sym unless block_type.nil? then @orig_type = block_type @type = normalise_type(block_type) else @orig_type = :none @type = :none end @target = header[1] end else @type = :none end @content.clear end
empty?()
click to toggle source
# File lib/bayeux/para_block.rb, line 45 def empty? return (@content.empty? or (/\S/ !~ @content)) end
normalise_type(type)
click to toggle source
Do type mapping if needed, otherwise pass on the contents as the type
# File lib/bayeux/para_block.rb, line 110 def normalise_type(type) case type when :e return :emph when :s return :strong when :quote return :block_quote else return type end end
orig_type_length()
click to toggle source
Returns the length of the type and target, as they were written out _in the original document_. For the current type length, see type_length
# File lib/bayeux/para_block.rb, line 56 def orig_type_length @orig_type.to_s.length + @target.to_s.length + 1 end
target()
click to toggle source
# File lib/bayeux/para_block.rb, line 33 def target @target end
target=(target)
click to toggle source
# File lib/bayeux/para_block.rb, line 30 def target=(target) @target = target end
to_debug_s()
click to toggle source
# File lib/bayeux/para_block.rb, line 164 def to_debug_s return "block type: #{type}, content: #{content}" end
to_json(*a)
click to toggle source
# File lib/bayeux/para_block.rb, line 172 def to_json(*a) begin require 'json' json_hash = { "type" => @name, "content" => @content, "target" => @target, JSON.create_id => self.class.name } return json_hash.to_json rescue LoadError warn "The JSON gem couldn't be loaded, and so the JSON representation could not be generated" end end
to_s()
click to toggle source
# File lib/bayeux/para_block.rb, line 160 def to_s @content.to_s end
to_sym()
click to toggle source
# File lib/bayeux/para_block.rb, line 168 def to_sym @content.to_sym end
type()
click to toggle source
# File lib/bayeux/para_block.rb, line 19 def type @type end
type=(type)
click to toggle source
Accessors
# File lib/bayeux/para_block.rb, line 16 def type=(type) @type = normalise_type(type) end
type_length()
click to toggle source
Returns the length of the type and target, as they would be written out (including the separator), e.g as ‘figure:L3’.length
# File lib/bayeux/para_block.rb, line 63 def type_length @type.to_s.length + @target.to_s.length + 1 end