new Data( GedCom , Caller )
Data class contains details of a property. Data has a value and other properties. All properties are also Data classes.
Parameters:
Name | Type | Description |
---|---|---|
GedCom |
GedCom | GedCom parser instance |
Caller |
mixed | Caller instance where the class has been called |
- Copyright:
-
- Dávid Imre 2016. See full of rights.
Extends
Members
-
callbacks :Object.<string, PropertySetter>
-
Callbacks are executed after a property has been set.
Type:
- Object.<string, PropertySetter>
-
(private) caller :mixed
-
Caller instance where the class has been called.
Type:
- mixed
-
(private) constructors :Array.<string>
-
Class chaining.
Type:
- Array.<string>
- Inherited From:
-
(private) gedcom :GedCom
-
GedCom parser instance.
Type:
-
(private) id :string|Number
-
Data ID.
Type:
- string|Number
-
(private) props :Properties
-
Data properties.
Type:
-
(private) value :mixed
-
Data value.
Type:
- mixed
Methods
-
extend( opts ) → {boolean}
-
Merge the contents of passed Object into the Self instance.
Parameters:
Name Type Description opts
Object Extended options - Inherited From:
Returns:
-
{boolean} - True if extending is succeeded, false otherwise
Example:
new Base().extend({ <property>: <value>, <method>: function(){ } });
-
fromObject( object , deep ) → {Data}
-
Imports properties from a specific primitive Object.
Parameters:
Name Type Description object
Object Object will be imported deep
boolean When true, the import will run recursively Returns:
-
{Data} - Self instance
Example:
new Data(<gedcom>, <instance>).fromObject(new Object({ props: { 'NAME': new Object({ props: { //RECURSIVELY }; value: <value>, type: 'Data' } }, value: <value>, type: 'Data' });
-
-
get( keys ) → {Data}
-
Get a Data property.
Parameters:
Name Type Description keys
array Keypath of the property Returns:
-
{Data} - Data property
Example:
new Data(<gedcom>, <instance>).get(['NAME', 'FIRST']);
-
-
(private) getCaller( ) → {Data}
-
Get the Data caller instance.
Returns:
-
{Data} - Self instance
Example:
new Data(<gedcom>, <instance>).getCaller();
-
-
getId( ) → {string|Number}
-
Get Data ID. Data ID is the key in parent Properties instance.
Returns:
-
{string|Number} - Data ID
Example:
new Data(<gedcom>, <instance>).getId();
-
-
(private) getKeyPath( keys ) → {KeyPath}
-
Get the KeyPath of a property from an Array.
Parameters:
Name Type Description keys
array Keypath of the property Returns:
-
{KeyPath} - Keypath of the property
Example:
new Data(<gedcom>, <instance>).getKeyPath(['NAME', 'FIRST']);
-
-
(private) getMethodName( [instance] , method [, method [, indexInStack]] ) → {string}
-
Get the method name.
Parameters:
Name Type Argument Description instance
mixed <optional>
A class instance method
function The method method
string <optional>
Calling stack, only used in strict mode indexInStack
number <optional>
Caller method index in stack, only used in strict mode - Inherited From:
Returns:
-
{string} - The method name
-
(private) getMethodParams( [instance] , method ) → {Array.<string>}
-
Get the method params.
Parameters:
Name Type Argument Description instance
mixed <optional>
A class instance method
string The method name - Inherited From:
Returns:
-
{Array.<string>} - The method params
-
(private) getProp( obj , keys ) → {Data}
-
Get a passed Data property.
Parameters:
Name Type Description obj
Data Passed Data keys
array Keypath of the property Returns:
-
{Data} - Passed Data property
Example:
new Data(<gedcom>, <instance>).get(new Data(<gedcom>, <instance>), ['NAME', 'FIRST']);
-
-
getType( ) → {string}
-
Get the type of a class.
- Inherited From:
Returns:
-
{string} - The type of a class
Examples:
new Properties(<gedcom>, <instance>).getType();
new List(<gedcom>, <instance>).getType();
new Data(<gedcom>, <instance>).getType();
-
(private) getValidKey( key )
-
Validates keys of a property.
Parameters:
Name Type Description key
string Key of the property Examples:
new Data(<gedcom>, <instance>).getValidKey('Birthday'); //returns "BIRT"
new Data(<gedcom>, <instance>).getValidKey('_Birthday'); //returns "_BIRT"
-
getValue( ) → {mixed}
-
Get Data value.
Returns:
-
{mixed} - Data value
Example:
new Data(<gedcom>, <instance>).getValue();
-
-
(private) init( instance )
-
Creates a class.
Parameters:
Name Type Description instance
function Self class - Inherited From:
-
remove( keys [, value [, index]] )
-
Removes a Data property.
Parameters:
Name Type Argument Description keys
array Keypath of the property value
mixed <optional>
Removed if property values matched passed valu index
mixed <optional>
Removed if property values index matched passed index Examples:
new Data(<gedcom>, <instance>).remove(['NAME', 'FIRST']);
new Data(<gedcom>, <instance>).remove(['NAME', 'FIRST'], 'Kevin');
new Data(<gedcom>, <instance>).remove(['NAME', 'FIRST'], undefined, 1);
-
(private) removeProp( obj , keys [, value [, index]] )
-
Removes a passed Data property.
Parameters:
Name Type Argument Description obj
Data Passed Data keys
array Keypath of the property value
mixed <optional>
Removed if property values matched passed value index
mixed <optional>
Removed if property values index matched passed index Examples:
new Data(<gedcom>, <instance>).remove(new Data(<gedcom>, <instance>), ['NAME', 'FIRST']);
new Data(<gedcom>, <instance>).remove(new Data(<gedcom>, <instance>), ['NAME', 'FIRST'], 'Kevin');
new Data(<gedcom>, <instance>).remove(new Data(<gedcom>, <instance>), ['NAME', 'FIRST'], undefined, 1);
-
(private) runCallback( obj , keys [, value [, keyPath]] ) → {mixed}
-
Runs callbacks after a property has been set.
Parameters:
Name Type Argument Description obj
Data Passed Data keys
array Keypath of the property value
mixed <optional>
Data value keyPath
KeyPath <optional>
Keypath of the property Returns:
-
{mixed} - Callback return value
Example:
new Data(<gedcom>, <instance>).runCallback(<referenced Data>, ['NAME', 'FIRST']);
-
-
set( keys [, value [, override]] ) → {Data}
-
Set a Data property.
Parameters:
Name Type Argument Description keys
array Keypath of the property value
mixed <optional>
New Data value override
boolean <optional>
When true, the existing value will be overridden Returns:
-
{Data} - Set property
Examples:
new Data(<gedcom>, <instance>).set(['NAME', 'FIRST'], 'Brian');
new Data(<gedcom>, <instance>).set(['NAME', 'FIRST'], 'Brian', true);
-
-
(private) setCaller( instance ) → {Data}
-
Set the Data caller instance.
Parameters:
Name Type Description instance
mixed Data caller instance Returns:
-
{Data} - Self instance
Example:
new Data(<gedcom>, <instance>).setCaller(<instance>);
-
-
setId( id ) → {Data}
-
Set Data ID.
Parameters:
Name Type Description id
string|Number New Data ID Returns:
-
{Data} - Self instance
Example:
new Data(<gedcom>, <instance>).setId(<ID>);
-
-
(private) setProp( obj , keys [, value [, override]] ) → {Data}
-
Set a passed Data property.
Parameters:
Name Type Argument Description obj
Data Passed Data keys
array Keypath of the property value
mixed <optional>
New passed Data value override
boolean <optional>
When true, the existing value will be overridden Returns:
-
{Data} - Set property of passed Data
Examples:
new Data(<gedcom>, <instance>).set(new Data(<gedcom>, <instance>), ['NAME', 'FIRST'], 'Brian');
new Data(<gedcom>, <instance>).set(new Data(<gedcom>, <instance>), ['NAME', 'FIRST'], 'Brian', true);
-
-
setValue( value [, override] ) → {mixed}
-
Set Data value.
Parameters:
Name Type Argument Description value
mixed New Data value override
boolean <optional>
When true, the existing value will be overridden Returns:
-
{mixed} - Self instance
Examples:
new Data(<gedcom>, <instance>).setValue(<value>);
new Data(<gedcom>, <instance>).setValue(<value>, true);
-
-
toDate( ) → {Date|NaN}
-
Converts Data to Date.
Returns:
-
{Date|NaN} - Data value as Date or NaN
Example:
new Data(<gedcom>, <instance>).toDate();
-
-
toGedCom( [indention [, suffix [, index]]] ) → {string}
-
Converts Data to GEDCOM structure string.
Parameters:
Name Type Argument Default Description indention
Number <optional>
0 Line indention suffix
string|Number <optional>
Line suffix index
Number <optional>
Value index when value is an array Returns:
-
{string} - GEDCOM structure string
Examples:
new Data(<gedcom>, <instance>).toGedCom();
new Data(<gedcom>, <instance>).toGedCom(1, <suffix>);
-
-
toObject( ) → {Object}
-
Converts Data to a specific pritimive Object.
Returns:
-
{Object} - Converted Data
Example:
new Data(<gedcom>, <instance>).toObject();
-
-
toString( returnMethod ) → {string}
-
Converts Data to string.
Parameters:
Name Type Description returnMethod
string Custom convert method to get Data value as string Returns:
-
{string} - Data value or type of Data if value is undefined
Examples:
new Data(<gedcom>, <instance>).toString();
new Data(<gedcom>, <instance>).toString('getId');
-