Skip to content

Instantly share code, notes, and snippets.

def print_triangle(size)
print_top_row_of_triangle(size)
return if size <= 1
print_middle_section_of_triangle(size)
print_bottom_of_triangle(size)
end
def print_triangle(size)
print_top_row_of_triangle(size)
return if size <= 1
print_middle_section_of_triangle(size)
print_bottom_of_triangle(size)
end
module RubyBBCode
def self.parse_youtube_id(url)
#url = "http://www.youtube.com/watch?v=E4Fbk52Mk1w"
url =~ /[vV]=([^&]*)/
id = $1
if id.nil?
module RubyBBCode
class TagInfo
def initialize(tag_info, tags)
@tag_data = find_tag_info(tag_info)
@tags = tags
@tag = @tags[@tag_data[:tag].to_sym] unless @tag_data[:tag].nil?
end
def [](key)
@tag_data[key]
module RubyBBCode
class TagInfo
def initialize(tag_info, tags)
@tag_data = find_tag_info(tag_info)
@tags = tags
@tag = @tags[@tag_data[:tag].to_sym] unless @tag_data[:tag].nil?
end
def [](key)
@tag_data[key]
module RubyBBCode
class TagInfo
def initialize(tag_info, tags)
@tag_data = find_tag_info(tag_info)
@tags = tags
@tag = @tags[@tag_data[:tag].to_sym] unless @tag_data[:tag].nil?
end
def [](key)
@tag_data[key]
module RubyBBCode
class TagInfo
def initialize(tag_info, tags)
@tag_data = find_tag_info(tag_info)
@tags = tags
@tag = @tags[@tag_data[:tag].to_sym] unless @tag_data[:tag].nil?
end
def [](key)
@tag_data[key]
module RubyBBCode
class TagInfo
def initialize(tag_info, tags)
@tag_data = find_tag_info(tag_info)
@tags = tags
@tag = @tags[@tag_data[:tag].to_sym] unless @tag_data[:tag].nil?
end
def [](key)
@tag_data[key]
def self.parse(text, tags = {})
tags = @@tags if tags == {}
@tag_collection = TagCollection.new(text, tags)
@tag_collection.process_text
if @tag_collection.invalid?
@tag_collection.errors
else
def process_text
@text.scan(/((\[ (\/)? (\w+) ((=[^\[\]]+) | (\s\w+=\w+)* | ([^\]]*))? \]) | ([^\[]+))/ix) do |tag_info|
@ti = TagInfo.new(tag_info, @defined_tags)
@ti.handle_unregistered_tags_as_text # if the tag isn't in the @defined_tags list, then treat it as text
return if !valid_element?
# Validation of tag succeeded, add to @tags_list and/or bbtree
if @ti.element_is_opening_tag?
element = {:is_tag => true, :tag => @ti[:tag].to_sym, :nodes => [] }