class Creq::Requirement
Constants
- SYSTEM_ATTRS
Attributes
attributes[R]
body[R]
id[R]
title[R]
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# File lib/creq/requirement.rb, line 20 def initialize(options = {}) super() @id = options[:id] @title = options[:title] || '' @body = options[:body] || '' @attributes = options .select{|k, _| ![:id, :title, :body].include?(k)} end
Public Instance Methods
each() { |self| ... }
click to toggle source
# File lib/creq/requirement.rb, line 83 def each(&block) return unless block_given? yield(self) items.each { |node| node.each(&block) } end
find(id)
click to toggle source
@param [String] requirement id; if the parameter contains the `*` prefix, it will search requirement.id.end_with?(id) @return [Requirement] when id found or nil if did not
# File lib/creq/requirement.rb, line 56 def find(id) each{|r| return r if r.id.end_with? id[2..-1]} if id.start_with? '..' each{|r| return r if r.id.eql? id} nil end
item(id)
click to toggle source
@param [String] requirement id; if the parameter contains the `.` prefix, it will search requirement.id.end_with?(id) @return [Requirement] when id found or nil if did not
# File lib/creq/requirement.rb, line 48 def item(id) @items.each{|r| return r if r.id.end_with? id[1..-1]} if id.start_with? '.' @items.each{|r| return r if r.id.eql? id} nil end
items()
click to toggle source
@return @items according to order in order_index attribute
# File lib/creq/requirement.rb, line 69 def items return @items if @items.empty? || @attributes[:order_index].nil? source = Array.new(@items) order = @attributes[:order_index] [].tap do |ordered| order.split(/ /).each do |o| e = source.delete(item(o)) ordered << e if e end ordered.concat(source) end end
links()
click to toggle source
@return requirements links from body
# File lib/creq/requirement.rb, line 63 def links return [] if @body.empty? @body.scan(/\[\[([\w\.]*)\]\]/).flatten.uniq end
parent_id()
click to toggle source
# File lib/creq/requirement.rb, line 41 def parent_id return @parent.id if @parent @attributes[:parent] end
system_attributes()
click to toggle source
# File lib/creq/requirement.rb, line 29 def system_attributes @attributes.select{|k, _| SYSTEM_ATTRS.include?(k)} end
user_attributes()
click to toggle source
# File lib/creq/requirement.rb, line 33 def user_attributes @attributes.select{|k, _| !SYSTEM_ATTRS.include?(k)} end
Protected Instance Methods
id=(id)
click to toggle source
protected to prevent assigning outside of Requirement
# File lib/creq/requirement.rb, line 94 def id=(id) @id = id end