class SocialSnippet::Tag
Attributes
path[R]
prefix[R]
ref[R]
repo[R]
spaces[R]
suffix[R]
Public Class Methods
get_path(s)
click to toggle source
Get path from given line
# File lib/social_snippet/tag.rb, line 191 def get_path(s) if is_snip_or_snippet_tag_line(s) # return snippet path (without repo name) path = ::Pathname.new(/<(.*?:)?(.*?)>/.match(s)[2]) return path.cleanpath.to_s end # return empty string return "" end
get_prefix(s)
click to toggle source
Get prefix from given line
# File lib/social_snippet/tag.rb, line 180 def get_prefix(s) if is_snip_or_snippet_tag_line(s) # return prefix text return /(.*?)@/.match(s)[1] end # return empty string return "" end
get_ref(s)
click to toggle source
Get repo’s ref from given line
# File lib/social_snippet/tag.rb, line 203 def get_ref(s) if is_tag_line_with_repository_have_ref(s) # return ref text return /<.+?#(.*?):/.match(s)[1] end return "" end
get_repo(s)
click to toggle source
Get repository name from given line
# File lib/social_snippet/tag.rb, line 213 def get_repo(s) if is_tag_line_with_repository(s) # return repository name return /<(.*?)[:#]/.match(s)[1] end # return empty string return "" end
get_spaces(s)
click to toggle source
Get spaces from given line
# File lib/social_snippet/tag.rb, line 158 def get_spaces(s) if is_snip_or_snippet_tag_line(s) # return spaces return /(@snip|@snippet)(\s*?)</.match(s)[2] end # return empty string return "" end
get_suffix(s)
click to toggle source
Get suffix from given line
# File lib/social_snippet/tag.rb, line 169 def get_suffix(s) if is_snip_or_snippet_tag_line(s) # return suffix text return />(.*)/.match(s)[1] end # return empty string return "" end
has_colon(s)
click to toggle source
Check given line to match ‘:` character
# File lib/social_snippet/tag.rb, line 144 def has_colon(s) return /:/ === s end
has_ref_text(s)
click to toggle source
Check given line to have ‘#` character
# File lib/social_snippet/tag.rb, line 139 def has_ref_text(s) return /<.*?#(.*?):/ === s end
is_begin_cut?(s)
click to toggle source
# File lib/social_snippet/tag.rb, line 115 def is_begin_cut?(s) /@begin_cut/ === s end
is_control_tag?(s)
click to toggle source
# File lib/social_snippet/tag.rb, line 103 def is_control_tag?(s) is_no_tag_line?(s) end
is_cut?(s)
click to toggle source
# File lib/social_snippet/tag.rb, line 111 def is_cut?(s) /@cut/ === s end
is_end_cut?(s)
click to toggle source
# File lib/social_snippet/tag.rb, line 119 def is_end_cut?(s) /@end_cut/ === s end
is_no_tag_line?(s)
click to toggle source
# File lib/social_snippet/tag.rb, line 107 def is_no_tag_line?(s) /@no_tag/ === s end
is_snip_or_snippet_tag_line(s)
click to toggle source
Check given line to match @snip or @snippet tag
# File lib/social_snippet/tag.rb, line 134 def is_snip_or_snippet_tag_line(s) return is_snip_tag_line(s) || is_snippet_tag_line(s) end
is_snip_tag_line(s)
click to toggle source
Check given line to match @snip tag
# File lib/social_snippet/tag.rb, line 124 def is_snip_tag_line(s) return /@snip\s*<.*?>/ === s end
is_snippet_tag_line(s)
click to toggle source
Check given line to match @snippet tag
# File lib/social_snippet/tag.rb, line 129 def is_snippet_tag_line(s) return /@snippet\s*<.*?>/ === s end
is_tag_line_with_repository(s)
click to toggle source
Check given line to match snippet tag with repo
# File lib/social_snippet/tag.rb, line 149 def is_tag_line_with_repository(s) return is_snip_or_snippet_tag_line(s) && has_colon(s) end
is_tag_line_with_repository_have_ref(s)
click to toggle source
# File lib/social_snippet/tag.rb, line 153 def is_tag_line_with_repository_have_ref(s) return is_tag_line_with_repository(s) && has_ref_text(s) end
new(s)
click to toggle source
Create instance
@param s [String] tag line text
# File lib/social_snippet/tag.rb, line 13 def initialize(s) set_path self.class.get_path(s) @repo = self.class.get_repo(s) @ref = self.class.get_ref(s) @prefix = self.class.get_prefix(s) @suffix = self.class.get_suffix(s) @spaces = self.class.get_spaces(s) # to normalize repo's path set_path self.class.get_path(s) end
Public Instance Methods
filename()
click to toggle source
# File lib/social_snippet/tag.rb, line 34 def filename ::Pathname.new(path).basename.to_s end
has_ref?()
click to toggle source
Check to have ref
# File lib/social_snippet/tag.rb, line 64 def has_ref? return ref.nil? === false && ref != "" end
has_repo?()
click to toggle source
Check to have repository
# File lib/social_snippet/tag.rb, line 69 def has_repo? return repo != "" end
normalize_path(path)
click to toggle source
# File lib/social_snippet/tag.rb, line 43 def normalize_path(path) # ././foo/bar => foo/bar path.gsub! /^\.\//, "" while /^\.\// === path # repo:/path/to/file -> repo:path/to/file path[0] = "" if has_repo? && path[0] == "/" path end
set_by_tag(base_tag)
click to toggle source
Set information by another tag
# File lib/social_snippet/tag.rb, line 26 def set_by_tag(base_tag) return self if base_tag.nil? @prefix = base_tag.prefix @suffix = base_tag.suffix @spaces = base_tag.spaces self end
set_path(new_path)
click to toggle source
Set path
# File lib/social_snippet/tag.rb, line 39 def set_path(new_path) @path = normalize_path(new_path) end
set_ref(new_ref)
click to toggle source
Set ref
# File lib/social_snippet/tag.rb, line 59 def set_ref(new_ref) @ref = new_ref end
set_repo(new_repo)
click to toggle source
Set repo
# File lib/social_snippet/tag.rb, line 54 def set_repo(new_repo) @repo = new_repo end
to_path()
click to toggle source
Get path text
# File lib/social_snippet/tag.rb, line 74 def to_path if has_repo? if has_ref? "#{repo}##{ref}:#{path}" else "#{repo}:#{path}" end else "#{path}" end end
to_snip_tag()
click to toggle source
Get @snip tag text
# File lib/social_snippet/tag.rb, line 92 def to_snip_tag return to_tag_text("@snip") end
to_snippet_tag()
click to toggle source
Get @snippet tag text
# File lib/social_snippet/tag.rb, line 97 def to_snippet_tag return to_tag_text("@snippet") end
to_tag_text(tag_text)
click to toggle source
Get tag text by given tag text
# File lib/social_snippet/tag.rb, line 87 def to_tag_text(tag_text) "#{prefix}#{tag_text}#{spaces}<#{to_path}>#{suffix}" end